WinFASM: FASM package for Windows
WinFASM is a flat assembler package containing tools to build 32-bit and 64-bit applications for the Microsoft Windows operating system on an Intel IA-32 or x86-64 architecture. Specifically, the package contains a set of include files with equates and macroinstructions that match many of the header files supplied in the Microsoft Platform SDK. Although WinFASM is directed toward 32- and 64-bit application development for the Windows operating system, it can be used to assemble 16-, 32- and 64-bit programs for other operating systems such as DOS, Linux and OpenBSD. However, it requires an x86 32-bit processor architecture to run.
This package is meant for programmers who are already familiar with the Windows API in some higher level programming language (especially C) but would like to complement their skills with some assembly language programming. But, please, don't let that scare you; even if you are a beginner, WinFASM may well help you in your learning process. The complete source code of flat assembler and many example programs are included in the package to assist you in this regard. If you have any questions, don't hesitate to make them known on the fasm message board; there are some really gentle individuals there waiting to reply your queries.
Installation & configuration
To install a copy of the WinFASM package, the first thing to do is to download one (just in case that step wasn't obvious). The package comes in a form of a ZIP archive so no UAC concerns are involved here. After all, as an assembly programmer, you shouldn't expect to be downloading MSI packages here—those kinda stuff are for the other guys! Afterwards, unzip it and place the inner folder named WinFASM at your preferred location, desirably at the root of your primary drive, e.g. drive C. At this point, you have successfully installed WinFASM on your computer.
Having completed the steps above, you may want to set an
INCLUDE environment variable pointing to the full path of the include folder inside the WinFASM root folder. Assuming you did precisely as outlined in the previous paragraph, your
INCLUDE variable should resolve to a path similar to C:\WinFASM\include. This step is highly recommended, and it is essential in order to eliminate the need of specifying the full on-disk path for your include files in your source code. Additionally, flat assembler looks up this variable when assembling programs.
Finally, you may want to add the bin directory path to your
PATH environment variable. (The bin folder contains the executable binaries shipped with WinFASM.) This ensures that you do not type out the full path to the location of flat assembler when you are assembling programs but can just type the basename of the application, that is
fasm. Inside the bin directory is also the official FASM IDE. If you do not have a favorite text editor that lets you compile assembly language without trouble, then make this one yours. OK, if you have completed all of the above procedures, then I guess you are ready to assemble your first assembly program.
GUI "Hello, world" example
This is not exactly a tutorial on how to program with WinFASM (I will write one later) but to show how easy and sweet it is to write applications with it. Below is a simple 32-bit Windows GUI application. The resulting application shows a message box with the text "Hello, world; assembly is easy!" and title "My WinFASM Application". After the user clicks the OK button of the dialog, it immediately exits. You can find many of such example programs in the examples folder in the WinFASM package. Nevertheless, you would have to grab for yourself a few assembly language programming books to study, mostly available for free on the Internet.
; Include the WinFASM primary include file. This file contains macros
; and definitions of various Windows API functions. You need them.
; The main application code begins. If you know any C-like language,
; then it would help for you to know that the code below translates:
; > MessageBox(NULL, szText, szTitle, MB_OK | MB_ICONINFORMATION);
; > ExitProcess(0);
push MB_OK or MB_ICONINFORMATION
; Did you notice the "szTitle", and "szText" labels above? Well, think
; of them as variables in high level languages. Let's declare them.
; Apparently, in assembly language, your "variables" can be anywhere :)
; The "dz" is a WinFASM equate used for transparent declaration of
; character strings, which would be encoded in either ANSI or Unicode.
szText dz "Hello, world; assembly is easy!",0
szTitle dz "My WinFASM Application",0
; We're done. The directive below tells WinFASM to insert some obscure,
; redundant and mundane information about the WinAPI functions that we
; called in our program above here, namely, MessageBox and ExitProcess.
To assemble the program in the snippet above, save the code into a file, and name it hello.asm, for example. Then invoke flat assembler and supply the name of the file containing the code as a parameter. The program will be assembled and a 32-bit Windows application generated in the same folder as the source file. (Additional information on using FASM can be found in the flat assembler Programmer's Manual PDF file which resides in the doc folder of the WinFASM package.) The output that you will see may be similar to the one below:
C:\> fasm hello.asm
flat assembler version 1.71.17 (65536 kilobytes memory)
generating code for 32-bit platform (ansi)
4 passes, 0.1 seconds, 1536 bytes.
Yes, that is the final executable program size—1,536 bytes! You can put those in your pocket and win the Olympics! As Steve Gibson would say: "Small is beautiful." How true is that!
Although there are several high level macro constructs you may use in your programs like
.while, etc. to simulate the syntax of high level languages, I do not recommend their usage. Remember (especially if you are a beginner) that the objective is to learn how to program in assembly language but not to port that your fancy Java enterprise application to it. So learn how to do stuff manually and make minimal use of macros. That should help you develop your assembly programming skills faster, however, perhaps, create more bugs but certainly gain "profound enlightenment" in this amazing field of programming.
|winfasm-0.1.0.zip||WinFASM 0.1.0-pre-ALPHA||1.00 MB|
The license that comes with this software (both the source code and compiled binaries) allows you to distribute, remix, tweak, and build upon your work, even commercially, as long as you credit the author for the original creation. See the in-package LICENSE.txt for additional information.