# AMD64 NASM Cheatsheet ## Sizes | Size (bits) | Size (bytes) | Name | NASM Mnemonics / Directives | |-------------|--------------|--------|----------------------------------------| | 8 | 1 | byte | DB, RESB | | 16 | 2 | word | DW, RESW | | 32 | 4 | dword | DD, RESD | | 64 | 8 | qword | DQ, RESQ | | 80 | 10 | tword | DT, REST | | 128 | 16 | oword | DO, RESO, DDQ, RESDQ | | 256 | 32 | yword | DY, RESY | | 512 | 64 | zword | DZ, RESZ | ## Registers | Register (32, 16, 8H, 8L)-bit | Usage | Preserved Across Function Calls | |--------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|---------------------------------| | %rax (eax, ax, ah, al) | Temporary register; with variable arguments passes information about the number of vector registers used; 1st return register | No | | %rbx (ebx, ax, ah, al) | Callee-saved register; optionally used as base pointer | Yes | | %rcx (ecx, cx, ch, cl) | Used to pass 4th integer argument to functions | No | | %rdx (edx, dx, dh, dl) | Used to pass 3rd argument to functions; 2nd return register | No | | %rsp (esp, sp, N/A, spl) | Stack pointer | Yes | | %rbp (ebp, bp, N/A, bpl) | Callee-saved register; optionally used as frame pointer | Yes | | %rsi (esi, si, N/A, sil) | Used to pass 2nd argument to functions | No | | %rdi (edi, di, N/A, dil) | Used to pass 1st argument to functions | No | | %r8 (r8d, r8w, N/A, r8b) | Used to pass 5th argument to functions | No | | %r9 (r9d, r9w, N/A, r9b) | Used to pass 6th argument to functions | No | | %r10 (r10d, r10w, N/A, r10b) | Temporary register, used for passing a function’s static chain pointer | No | | %r11 (r11d, r11w, N/A, r11b) | Temporary register | No | | %r12–%r15 (r12-15d, r12-15w, N/A, r12-15b) | Callee-saved registers | Yes | | %xmm0–%xmm1 | Used to pass and return floating point arguments | No | | %xmm2–%xmm7 | Used to pass floating point arguments | No | | %xmm8–%xmm15 | Temporary registers | No | | %mmx0–%mmx7 | Temporary registers | No | | %st0, %st1 | Temporary registers; used to return long double arguments | No | | %st2–%st7 | Temporary registers | No | | %fs | Reserved for system (as thread specific data register) | No | | mxcsr | SSE2 control and status word | Partial | | x87 SW | x87 status word | No | | x87 CW | x87 control word | Yes | ## Instructions ### Conditional JUMP Instructions
Instruction Description signed-ness Flags short
jump
opcodes
near
jump
opcodes
JO Jump if overflow   OF = 1 70 0F 80
JNO Jump if not overflow   OF = 0 71 0F 81
JS Jump if sign   SF = 1 78 0F 88
JNS Jump if not sign   SF = 0 79 0F 89
JE
JZ
Jump if equal
Jump if zero
  ZF = 1 74 0F 84
JNE
JNZ
Jump if not equal
Jump if not zero
  ZF = 0 75 0F 85
JB
JNAE
JC
Jump if below
Jump if not above or equal
Jump if carry
unsigned CF = 1 72 0F 82
JNB
JAE
JNC
Jump if not below
Jump if above or equal
Jump if not carry
unsigned CF = 0 73 0F 83
JBE
JNA
Jump if below or equal
Jump if not above
unsigned CF = 1 or ZF = 1 76 0F 86
JA
JNBE
Jump if above
Jump if not below or equal
unsigned CF = 0 and ZF = 0 77 0F 87
JL
JNGE
Jump if less
Jump if not greater or equal
signed SF <> OF 7C 0F 8C
JGE
JNL
Jump if greater or equal
Jump if not less
signed SF = OF 7D 0F 8D
JLE
JNG
Jump if less or equal
Jump if not greater
signed ZF = 1 or SF <> OF 7E 0F 8E
JG
JNLE
Jump if greater
Jump if not less or equal
signed ZF = 0 and SF = OF 7F 0F 8F
JP
JPE
Jump if parity
Jump if parity even
  PF = 1 7A 0F 8A
JNP
JPO
Jump if not parity
Jump if parity odd
  PF = 0 7B 0F 8B
JCXZ
JECXZ
Jump if %CX register is 0
Jump if %ECX register is 0
  %CX = 0
%ECX = 0
E3  
Source: Intel x86 JUMP quick reference ## additional resources [Linux syscalls](https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/) [System V AMD64 ABI](https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf) [Getting arguments](https://github.com/tonyOreglia/argument-counter/wiki/x86-64-Linux-Assembly-Part-1:-Printing-Command-Line-Arguments) [x86 and amd64 instruction reference](https://www.felixcloutier.com/x86/)