The Hello World Program

The first program we look at is a simple Windows "Hello World" program:

include '%fasminc%/win32ax.inc'

.code

  start:
        invoke  MessageBox,HWND_DESKTOP,"Hello World!","Win32 Assembly",MB_OK
        invoke  ExitProcess,0

.end start 

The first line includes a special macro file win32ax.inc which contains all the nasty business that you don't want to see when writing a Windows program.

The next line tells the assembler we are going to include some code now.

The line start: is simply a label. It just gives a name to one of the lines of our program so we can refer to it elsewhere. We'll use labels often, for example when writing loops or using other jump instructions. The label will simply allow us to refer to that particular location within our code, by name; say for example if we wanted to jump to that location from somewhere else.

The program is ended with the .end directive. It takes one parameter, the name of a label corresponding to the entry point of the program (which doesn't need to be at the start of the program). When the program is loaded into memory by the operating system, execution of the program will begin at this point.

top

Windows API Calls

The remaining two lines are calls to the Windows API to tell it to display a message box and then quit.

You'll need a decent Win32 API Reference if you want to write Windows programs. You can download one from the documentation section of the FASM website.

The other features on these lines of code are parameters sent to the corresponding API functions, MessageBox and ExitProcess. Two of the constants used, are given names by the win32ax.inc file that we included. These are also the names given to these constants in the Win32 API reference. We defer discussing Win32 programming until later in the tutorial. But it is useful to see right from the start that FASM makes Win32 programming very easy.