Assembly

x86 and amd64 instruction reference

Registers & Function Call

chevron-rightx86 Registers (32-bit)hashtag

With the x86 elf architecture, arguments are passed on the stack.

Byte 0-3
Bytes 0-1
Byte 0
Typical usage

eax

ax

al

Accumulator (arithmetic results) Return Value

ebx

bx

bl

Base register (addresses, general use)

ecx

cx

cl

Counter (loops, shifts)

edx

dx

dl

Data, multiplication/division

esi

si

/

Source index (strings, arrays)

edi

di

/

Destination index (strings, arrays)

esp

sp

/

Stack pointer (top of the stack)

ebp

bp

/

Base/frame pointer (stack frames)

eip

/

/

Extended Instruction Pointer (next instruction)

chevron-rightx64 Registers (64-bit)hashtag

In x64 linux arguments to a function are passed via registers.

Byte 0-7
Bytes 0-3
Bytes 0-1
Byte 0
Typical usage

rax

eax

ax

al

Accumulator (arithmetic results) Return Value

rbx

ebx

bx

bl

Base register (addresses, general use)

rcx

ecx

cx

cl

Counter (loops, shifts) 4. Fourth Argument

rdx

edx

dx

dl

Data, multiplication/division 3. Third Argument

rsi

esi

si

sil

Source index (strings, arrays) 2. Second Argument

rdi

edi

di

dil

Destination index (strings, arrays) 1. First Argument

rsp

esp

sp

spl

Stack pointer (top of the stack)

rbp

ebp

bp

bpl

Base/frame pointer (stack frames)

r8

r8d

r8w

r8b

General-purpose 5. Fifth Argument

r9

r9d

r9w

r9b

General-purpose 6. Sixth Argument

r10

r10d

r10w

r10b

General-purpose

r11

r11d

r11w

r11b

General-purpose

r12

r12d

r12w

r12b

General-purpose

r13

r13d

r13w

r13b

General-purpose

r14

r14d

r14w

r14b

General-purpose

r15

r15d

r15w

r15b

General-purpose

rip

eip

/

/

Register Instruction Pointer (next instruction)

chevron-rightFunction Callhashtag
     +-----------------+ 0x00000000
     |       ...       |
  +- +-----------------+ <- ESP
  |  |     Old EIP     |
F |  +-----------------+
R |  |       ...       |
A |  |       ...       |
M |  | Local Variable  | 
E |  +-----------------+ <-- EBP = Old ESP
  |  |     Old EBP     |
  +- +-----------------+
     |     Old EIP     | <-- Return Address
     +-----------------+
     |       ...       |
     +-----------------+ 0xffffffff

call function ; push eip
              ; jmp function

Prologue

push ebp     ; save the old base pointer
mov ebp, esp ; save esp in ebp
sub esp, x   ; allocate space for local variables

Epilogue

leave  ; mov esp, ebp  ; restore esp
       ; pop ebp       ; restore ebp
ret    ; pop eip       ; restore execution
chevron-rightWordshashtag

word 2 bytes of data.

dword 4 bytes of data.

qword 8 bytes of data.

Instructions & Note

chevron-rightPracticehashtag

MOV

Dereferencing []

LEA

ADD

SUB

PUSH

POP

CMP

JMP

JE/JNE/JG/JL/JZ/JNZ

XOR/AND/OR

Last updated