Here's the full list of ordinary integer x86 registers. The 64 bit registers are shown in red. "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.
Name |
Notes | Type |
64-bit long |
32-bit int |
16-bit short |
8-bit char |
rax |
Values are returned from
functions in this register. |
scratch |
rax | eax | ax | ah and al |
rcx |
Typical scratch register. Some instructions also use it as a counter. | scratch |
rcx | ecx | cx | ch and cl |
rdx |
Scratch register. | scratch |
rdx | edx | dx | dh and dl |
rbx |
Preserved register: don't use it without saving it! | preserved |
rbx | ebx | bx | bh and bl |
rsp |
The
stack pointer. Points to the top of the stack
(details coming soon!) |
preserved | rsp | esp | sp | spl |
rbp |
Preserved register. Sometimes used to store the old value of the stack pointer, or the "base". | preserved | rbp | ebp | bp | bpl |
rsi |
Scratch register used to pass
function argument #2 in 64-bit Linux. In 64-bit
Windows, a preserved register. |
scratch | rsi | esi | si | sil |
rdi |
Scratch register and function
argument #1 in 64-bit Linux. In 64-bit Windows, a
preserved register. |
scratch | rdi | edi | di | dil |
r8 |
Scratch register. These
were added in 64-bit mode, so they have numbers, not names. |
scratch | r8 | r8d | r8w | r8b |
r9 |
Scratch register. | scratch | r9 | r9d | r9w | r9b |
r10 |
Scratch register. | scratch | r10 | r10d | r10w | r10b |
r11 |
Scratch register. | scratch | r11 | r11d | r11w | r11b |
r12 |
Preserved
register. You can use it, but you need to save and
restore it. |
preserved | r12 | r12d | r12w | r12b |
r13 |
Preserved register. | preserved | r13 | r13d | r13w | r13b |
r14 |
Preserved register. | preserved | r14 | r14d | r14w | r14b |
r15 |
Preserved register. | preserved | r15 | r15d | r15w | r15b |
extern putchar mov rdi,'H' ; function parameter: one char to print call putchar
sub rsp,32+8; parameter area, and stack alignment extern putchar mov rcx,'H' ; function parameter: one char to print call putchar add rsp,32+8 ; clean up stack
Source
Size |
|||||
64 bit rcx |
32 bit ecx |
16 bit cx |
8 bit cl |
Notes |
|
64 bit rax |
mov rax,rcx |
movsxd rax,ecx |
movsx rax,cx |
movsx rax,cl |
Writes to whole register |
32 bit eax |
mov eax,ecx |
mov eax,ecx |
movsx eax,cx |
movsx eax,cl |
Top half of destination gets zeroed |
16 bit ax |
mov ax,cx |
mov ax,cx |
mov ax,cx |
movsx ax,cl |
Only affects low 16 bits, rest unchanged. |
8 bit al |
mov al,cl |
mov al,cl | mov al,cl | mov al,cl |
Only affects low 8 bits, rest unchanged. |
C/C++ datatype | Bits | Bytes | Register | Access memory | Allocate memory |
char | 8 | 1 | al | BYTE [ptr] | db |
short | 16 | 2 | ax | WORD [ptr] | dw |
int | 32 | 4 | eax | DWORD [ptr] | dd |
long | 64 | 8 | rax | QWORD [ptr] | dq |
Instructions (basically identical to 32-bit x86)For gory instruction set details, read this per-instruction reference, or the full Intel PDFs: part 1 (A-M) and part 2 (N-Z).
|
|||||||||||||||||||||||||||||||||||||||
Constants, Registers, Memory"12" means decimal 12; "0xF0" is hex. "some_function" is the address of the first instruction of the function. Memory access (use register as pointer): "[rax]". Same as C "*rax".Memory access with offset (use register + offset as pointer): "[rax+4]". Same as C "*(rax+4)". Memory access with scaled index (register + another register * scale): "[rax+rbx*4]". Same as C "*(rax+rbx*4)". |