x86-64 Assembly Cheatsheet

Data Transfer Instructions

These instructions move data between registers, memory, and immediate values.

mov (Move)

  • Transfers data from one place to another (register-to-register, memory-to-register, etc.).

  • Does not modify the original value; just copies it.

mov rax, 10    ; Store 10 in register RAX
mov rbx, rax   ; Copy the value of RAX into RBX
mov rcx, [var] ; Load value from memory address "var" into RCX

lea (Load Effective Address)

  • Loads the memory address of a variable instead of its value.

  • Useful for pointer arithmetic.

lea rax, [var] ; Load the memory address of "var" into RAX

Arithmetic Instructions

These instructions perform mathematical operations on registers and memory.

inc (Increment)

  • Increases a value by 1.

dec (Decrement)

  • Decreases a value by 1.

add (Addition)

  • Adds a value to a register or memory location.

sub (Subtraction)

  • Subtracts a value from a register or memory location.


Logical Instructions

Used for bitwise operations (AND, OR, XOR, NOT).

and (Bitwise AND)

  • Compares bits and sets result only if both bits are 1.

or (Bitwise OR)

  • Compares bits and sets result if either bit is 1.

xor (Bitwise XOR)

  • Flips bits where corresponding bits differ (commonly used for clearing registers).

not (Bitwise NOT)

  • Flips all bits (inverts 0s to 1s and vice versa).


Comparison Instructions

Used to compare values and set flags for conditional execution.

cmp (Compare)

  • Subtracts two values without storing the result, but sets flags to indicate the relationship (equal, greater, less, etc.).

test (Bitwise Test)

  • Performs a bitwise AND, but doesn’t store the result—only sets flags.


Branch (Jump) Instructions

Used for decision-making and loops.

jmp (Jump)

  • Moves execution to a different part of the program (unconditional).

Conditional Jumps (je, jg, etc.)

  • je (Jump if Equal) – Jumps if the last cmp resulted in equality.

  • jg (Jump if Greater) – Jumps if the first value was greater.


Stack Instructions

Used for storing and retrieving data from the stack.

push (Push onto Stack)

  • Saves a value onto the stack.

pop (Pop from Stack)

  • Retrieves the most recently pushed value from the stack.


Procedure Instructions

Used for calling and returning from functions.

call (Function Call)

  • Jumps to a function and saves the return address on the stack.

ret (Return from Function)

  • Returns to the calling function by popping the saved return address from the stack.

leave (Cleanup for Stack Frames)

  • Used to exit a function properly by restoring the base pointer.


System Call Instruction

Used for interacting with the operating system (Linux syscalls).

syscall (System Call)

  • Executes a system call (e.g., printing to the console, exiting a program).

Last updated