NASM Assembly Quick Reference Guide - 32-Bit
Sources
Registers (Quick list:)
Registers |
Usage |
---|---|
|
Use and overwrite |
|
Preserved. You must preserve the values and return them |
Instructions
Command |
Direction |
---|---|
mov x, y |
x ← y |
and x, y |
x ← x and y |
or x, y |
x ← x or y |
xor x, y |
x ← x xor y |
add x, y |
x ← x + y |
sub x, y |
x ← x - y |
inc x |
x ← x + 1 |
dec x |
x ← x - 1 |
syscall |
Invoke an operating system routine |
Note
Take note of the specific registers in the table. The operation stores the result in register EAX, but uses other registers.
Command |
Stored Result |
Notes |
---|---|---|
|
eax ← eax * eax |
Results go to EAX. |
|
eax ← eax * x |
Multiplies EAX with the value in the other register. |
|
eax ← eax / ecx |
Divides EAX by the value in the register by EAX. |
Detailed List
Mnemonic |
Purpose |
Examples |
|
|
; Load constant into eax
mov eax, 4
; Copy eax into ebx
mov ebx, eax
; Copy ebx to memory
; address 123
mov ebx, [123]
|
|
|
|
|
Remove topmost value from the stack. Equivalent to
|
|
esp, 4
esp, 8
esp, 12
|
|
; Pop the last value
;from the stack
esp, 4
|
|
|
|
|
|
|
|
|
; Add ebx to eax
add eax,ebx
|
|
|
;Multiply eax by ebx
mul ebx
|
|
|
jmp post_mem
...
post_mem:
|
|
|
|
jl label
jle label
je label
jge label
jg label
jne label
jz label
jnz label
|
Goto label if previous comparison was:
|
cmp eax, 10
; Jump if eax < 10
jl loop_start
|
cmovl a, b
cmovg a, b
|
Move if the previous comparison was:
|
cmp eax, 10
; eax = ecx if eax < 10
cmovl eax, ecx
|
Registers 8-32 bit (Full List)
Full list of ordinary integer x86 registers.
Scratch registers any function is allowed to overwrite and use for anything you want without asking anybody.
Preserved registers have to be put back (“save” the register) if you use them.
Notes |
Type |
32-bit int |
16-bit short |
8-bit char |
---|---|---|---|---|
Values are returned from |
scratch |
eax |
ax |
ah and al |
Typical scratch register. Some |
scratch |
ecx |
cx |
ch and cl |
Scratch register. |
scratch |
edx |
dx |
dh and dl |
Preserved register: don’t use |
preserved |
ebx |
bx |
bh and bl |
The stack pointer. Points to |
preserved |
esp |
sp |
|
Preserved register. Sometimes |
preserved |
ebp |
bp |
|
Preserved register. You can |
scratch |
esi |
si |
|
Preserved register. You can |
scratch |
edi |
di |