Programming with FASM – first steps .

By | 30/04/2012

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.

The FASMW is a GUI to help in programming, as shown here.

fasmw GUI

Let’s see some example and how this working…

In this first example, you will see a message box.

See result in the image shown below:

fasm message box

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:

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:

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:

It seemed more complicated and structured differently from the first example.

Let’s see the result.

fasm another example

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.

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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.