The FASM is a self-assembling open-source 80×86 assembler forDOS, Windows and Linux.
It supports all 8086-80486/Pentium instructions with MMX, SSE, SSE2 and with more features.
FASM contains many programming options and features.
The source code can be written in different ways because of control directives, macros, and management of resources.
FASM, by default, uses the Intel syntax for the assembly instructions.
You can go on and download it.
Below we see the files that are used by FASM.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | FASM.EXE = command line fasm FASMW.EXE = GUI fasm FASMW.INI = config file of fasmw INCLUDE = INCLUDE folder with all source | WIN32A.INC | WIN32AX.INC | WIN32AXP.INC | WIN32W.INC | WIN32WX.INC | WIN32WXP.INC | WIN64A.INC | WIN64AX.INC | WIN64AXP.INC | WIN64W.INC | WIN64WX.INC | WIN64WXP.INC | cont.txt | +---API | ADVAPI32.INC | COMCTL32.INC | COMDLG32.INC | GDI32.INC | KERNEL32.INC | SHELL32.INC | USER32.INC | WSOCK32.INC | +---ENCODING | UTF8.INC | WIN1250.INC | WIN1251.INC | WIN1252.INC | WIN1253.INC | WIN1254.INC | WIN1255.INC | WIN1256.INC | WIN1257.INC | WIN1258.INC | WIN874.INC | +---EQUATES | COMCTL32.INC | COMCTL64.INC | COMDLG32.INC | COMDLG64.INC | GDI32.INC | KERNEL32.INC | KERNEL64.INC | SHELL32.INC | SHELL64.INC | USER32.INC | USER64.INC | WSOCK32.INC | +---MACRO | COM32.INC | COM64.INC | EXPORT.INC | IF.INC | IMPORT32.INC | IMPORT64.INC | MASM.INC | PROC32.INC | PROC64.INC | resource.bin | RESOURCE.INC | STRUCT.INC | +---PCOUNT ADVAPI32.INC COMCTL32.INC COMDLG32.INC GDI32.INC KERNEL32.INC SHELL32.INC USER32.INC WSOCK32.INC |
The FASMW is a GUI to help in programming, as shown here.
Let’s see some example and how this working…
In this first example, you will see a message box.
1 2 3 4 5 6 7 8 9 10 11 12 13 | include '\include\win32ax.inc' _hello db 'Hello World',0 _title db 'Title of dialog',0 start: push MB_OKCANCEL push _title push _hello push NULL call [MessageBox] push 0 call [ExitProcess] .end start |
See result in the image shown below:
The first line includes some macro – functions.
If the source code is another folder, like for example in a folder named asm in the same folder with INCLUDE, then you need to declare these macros in this way:
1 | include '..\INCLUDE\WIN32A.INC' |
As you see the FASM is not case sensitive, in this case.
The next two lines are data declarations.
Code execution takes place between the two labels:
1 2 3 4 | start: ... .end start |
The code between these labels is written in assembler and can be easy recognized.
If you think it is easy then let’s see a second example, here’s the source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | format PE console entry main include 'INCLUDE\MACRO\import32.inc' section '.data' data readable writeable msg db "hello world!",0 p db "pause>nul",0 section '.code' code readable executable main: push ebp mov ebp,esp sub ebp,4 mov dword [esp],msg call [printf] mov dword [esp],p call [system] mov dword [esp],0 call [exit] section '.idata' import data readable library msvcrt,'msvcrt.dll' import msvcrt,\ printf,'printf',\ system,'system',\ exit,'exit' |
It seemed more complicated and structured differently from the first example.
Let’s see the result.
As I said above, FASM – The flat assembler is a series of directives and special words.
That helps us if we know, if not then we use what we know.
Let’s look at the source code of the second example and try to understand it a bit.
1 | format PE console |
This tells us about creating a PE file for the x86-64 architecture or if you want to use PE64 keyword instead of PE in the format declaration.
This selects the Portable Executable output format and will be a console application.
Also can be console or GUI for Windows applications, native for Windows drivers, EFI, EFIboot or EFIruntime for the UEFI or optional DLL and WDM.
Next entry directive sets the entry point for MZ executable.
The section directive defines a new section and it should be followed by flags.
We have three sections in this instance one for data, one for code and one for other data.
Other source code lines are easily recognized by how they were reported in these sections.
I hope you enjoyed the tutorial, I will expect you to come and other tutorials.