Programming with FASM – first steps with x86-64 example.

This tutorial follows the old tutorial in the FASM programming series, see Programming with FASM – first steps.
The FASM manual that follows this example can be found here.
This is an example:

As you can see is need to set the format and included file: PE64 GUI and win64ax.inc.
The .data and .code area are the same steps as any programming with the call instructions (but it is not mandatory, but for the beginning, it is very good).
Now about the Windows MessageBox Windows function named MessageBox, this takes four arguments.

We need to use the xor to fix and prepare the lea for load strings.
The x64 registers: RCX, RDX, R8, R9 are used for integer and pointer arguments in that order left to right.
Let’s parse some simple examples with xor versus registers in order to see the sized data:

The next step is the lea:
The FASM manual tells us:
The source operand must be a memory operand, and the destination operand must be a general register.
lea dx,[bx+si+1] ; load effective address to dx

Now I explain the basic rules as simple as possible, but the derivations are very complex and they become the rules of addressing.
Here are the basic rules:
The Intel assembler uses the opposite order (destination <- source) for operands.
Operands can be immediate (that is, constant expressions that evaluate to an inline value), register (a value in the processor number registers), or memory (a value stored in memory). An indirect operand contains the address of the actual operand value.

In FASM, when you write “[X]”, you are referring to the variable X.
If you write just X, you are referring to its address of X.
The lea is like the & in C programming.

Leave a Reply

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