X86 Assembly/FASM Syntax

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

FASM is an assembler for the IA-32 architecture. The name stands for "[1]flat assembler". FASM itself is written in assembly language and is also available on DOS, DexOS, Linux, Windows, and MenuetOS systems. It shatters the "assembly is not portable at all" myth. FASM has some features that are advanced for assembly languages, such as macros, structures, and "virtual data". FASM contains bindings to the MSWindows GUI and OpenGL.

Contents

[edit] $FFFF 0xffff ffffh

FASM supports all popular syntaxes of hex numbers.

[edit] @@ @f @b

Anonymous labels are supported. Example:

@@: inc eax
    push eax
    jmp @b     ; This will result in a stack fault sooner or later
 

[edit] $

$ describes current location. Useful for determining the size of a block of code or data. Example of use:

mystring           db    "This is my string", 0
mystring.length    equ   $-mystring

[edit] Local Labels

Local Labels, which begin with a . (a period)

globallabel:

.locallabelone:

.locallabeltwo:

globallabel2:

.locallabelone:

.locallabeltwo:

You can reference local labels from their global label. For example:

globallabel.locallabelone

[edit] Macros

Macros in FASM are described in a C-like manner and are created like this:

macro (name) (parameters) {
  macro code.
}

For example, the following could be used to overload the mov instruction to accept three parameters in FASM:

   macro mov op1,op2,op3
    {
     if op3 eq
       mov   op1,op2
     else
       mov   op1,op2
       mov   op2,op3
     end if
    }

if op3 eq means "If the 3rd parameter (op3) equals nothing, or blank" then do a normal mov operation. Else, do the 3 way move operation.

[edit] External links