Skip to main content

x86-64

Registers

General Purpose Registers (64-bit)

  • RAX, RBX, RCX, RDX
  • RSI, RDI, RBP, RSP
  • R8-R15

Segment Registers

  • CS, DS, ES, FS, GS, SS

Index Registers

  • RSI (Source Index)
  • RDI (Destination Index)

Data Movement

MOV: Move data between registers or memory

  • MOV reg, imm
  • MOV reg, mem
  • MOV mem, reg

Arithmetic and Logic

ADD, SUB, IMUL, IDIV, INC, DEC

  • ADD dest, src
  • SUB dest, src
  • IMUL dest, src (signed multiplication)
  • IDIV divisor (signed division)
  • INC reg/mem, DEC reg/mem

AND, OR, XOR, NOT

  • AND dest, src
  • OR dest, src
  • XOR dest, src
  • NOT reg/mem

Control Flow

JMP, JE (Jump if Equal), JNE (Jump if Not Equal), JG, JL, JGE, JLE

  • JMP label
  • JE label
  • JNE label
  • JG label (greater)
  • JL label (less)
  • JGE label (greater or equal)
  • JLE label (less or equal)

CALL, RET

  • CALL procedure
  • RET

Comparison

CMP: Compare two values

  • CMP operand1, operand2

Stack

PUSH, POP

  • PUSH reg/mem
  • POP reg/mem

System Calls

SYSCALL

  • Used for making system calls in x64 assembly.

Example Code

section .data
my_variable dq 42 ; Define a 64-bit variable with initial value 42

section .text
global _start

_start:
MOV RAX, my_variable ; Load my_variable into RAX
ADD RAX, 8 ; Add 8 to RAX
MOV RBX, 10 ; Load 10 into RBX
CMP RAX, RBX ; Compare RAX and RBX
JE equal_label ; Jump to equal_label if RAX equals RBX
JNE not_equal_label ; Jump to not_equal_label if RAX doesn't equal RBX

equal_label:
; Code to execute if RAX equals RBX
JMP end_label ; Jump to end_label

not_equal_label:
; Code to execute if RAX doesn't equal RBX

end_label:
; Code to execute at the end of the program
MOV RAX, 60 ; syscall: exit
XOR RDI, RDI ; status: 0
SYSCALL