Assembly is an extremely low-level human-readable language that has a strong relation between the code and the corresponding machine code.

If you are just getting started with assembly, I highly recommend you get started by first checking out the paper computing page to get familiar with the foundations and fundamentals of assembly language.

Compilation and Linking

For more specifics, visit the OSX and Windows assembly pages.

You will first need a program to compile your assembly into machine code. Most common is the program nasm for Unix systems and masm for Windows systems.

After you have written your code, you will need to assemble your code, translating it from the human readable assembly language into a file object.

You will then need to link your newly created output file. This will pull all the needed libraries into a single executable.

Syntax and Keywords


Command Effect
mov x, y xy
and x, y xx & y
or x, y xx | y
xor x, y xx ^ y
add x, y xx + y
sub x, y xxy
mul x EAXEAX * x
div x EAXEAX ÷ x
inc x xx + 1
dec x xx – 1


Command Effect
cmp x, y Set the
jmp label When this line is reached, jump to the line labeled label
je label / jz label When ZF is 0, jump to label
jne label / jnz label When ZF is NOT 0, jump to label


Command Effect
syscall Invoke an operating system routine
db A pseudo-instruction that declares bytes that will be in memory when the program runs


A section is an assembler directive that tells the assembler what kind of code follows. Generally, you put code in a section called .text and your constant data in a section called .data.


32-Bit General Purpose

Address Name Description
EAX Accumulator Register calculations for operations and results data
EBX Base Register pointer to data in the DS segment
ECX Count Register counter for string and loop operations
EDX Data Register input/output pointer
ESI Source Index source pointer for string operations
EDI Destination Index destination pointer for string operations
ESP Stack Pointer stack pointer, should not be used
EBP Base Pointer pointer to data on the stack

16-Bit Segment

Address Name Description
CS Code Segment where instructions being executed are stored
DS, ES, FS, GS Data Segment data segment
SS Stack Segment where the stack for the current program is stored

32-Bit Other

Address Name Description
EFLAGS Code Segment status, control, and system flags
EIP Instruction Pointer offset for the next instruction to be executed


Carry Flag (CF)

The carry flag is set to 1 (true) when the second operand of an operation is smaller than the first. For example if you cmp 2 1, the result will be a CF of 1 (true), since 1 - 2 goes negative, meaning that the first operand is larger than the first.

Overflow Flag (OF)

The overflow flag will be set to 1 (true) if the operation overflows beyond the bounds of the integers and their storage. This could happen if you are dealing with numbers that go beyond the boundaries involved (e.g. adding two numbers that go above 256 with an 8-bit unsigned integer, or adding two 8-bit unsigned integers that go beyond 128).

Sign Flag (SF)

The sign flag will be set to 1 (true) after an arithmetic operation when the result is negative.

Zero Flag (ZF)

The zero flag is set after an arithmetic operation and will have a value of 1 (true) when the result is zero, and 0 (false) when the result is not zero.


The stack is used to invoke a function or as temporary storage by pushing parameters in last in first out to be utilized by the function.

This will push the number 3 onto the stack and then write it to the EAX register.

push 3
pop eax

This will push three values to the stack in reverse order of what the function expects, because LIFO, and then invokes the function, which will use those values.

push [var] ; Push last parameter first
push 216   ; Push the second parameter
push eax   ; Push first parameter last

call _myFunc ; Call the function (assume C naming)

add esp, 12  ; Flush the three 4 byte values on the stack by 
      ; adding 12 to the stack pointer


There are lots of games that have recently come out to make assembly a little more accessible. Here are the references I have found and heard about from others:



Last modified: 202109270029