Skip to content

Instantly share code, notes, and snippets.

@rpip
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpip/b50c47f2aa75e574870a to your computer and use it in GitHub Desktop.
Save rpip/b50c47f2aa75e574870a to your computer and use it in GitHub Desktop.
my study notes ASM x86/i386

x86 / IA-32 registers

  • register is 32 bit wide

general registers

  1. eax - accumulator
  2. ebx - base
  3. ecx - counter
  4. edx - data
  5. esi - source index
  6. edi - destination index

special registers

  1. esp - stack pointer
  2. ebp - base pointer

x86-x64 architectures

  • register is 64 bit wide
  • an x86-64 register contains a 32-bit section
  • no stack operations required

misc

  • %(register) => memory location
  • memory is like an array(index -> value) ==> MEM[index] -> VALUE
  • displacement memory address mode ==> 8(%ebp) == MEM[ebp + 8]
  • indirect mode => %(ebp) | %ebp
  • state = memory + register + stack
  • gcc -S => generates / compiles to ASM
  • switch cases in ASM are implemented using JUMP tables

addressing modes

  • (Rb, Ri) == MEM[REGISTER[Rb] + REGISTER[Ri]]
  • D(Ri) == MEM[REGISTER[Ri] + D]
  • (Rb, Ri, D) == MEM[REGISTER[Rb] + REGISTER[Ri] * D]
  • (, Ri,D) == MEM[REGISTER[Ri] * D]
  • leal (set dst to address mode expression) => leal (%edx, ecx, 4), %eax
  • %eip - instruction pointer => pointer to next instruction to execute

operations

  • load - load from register into memory
  • store - store data in memory into a register

movX src dest, where X in [b | w | l]

b = 1 byte
w = 2 bytes
l = 4 bytes
src  = (memory) | register

conditional flags

  • CF => set if result of operation is signed or positive
  • SF => set if result of operation is unsigned or negative
  • ZF => set if result of operation is zero (0)
  • OF => set if result of operation is greater than the memory available or stack space

memory layout

Sorry, no fancy graphics available at the moment.

  1. instructions (executable)
  2. literals (non-executable)
  3. static data (constants, global vars)
  4. dynamic data (HEAP, managed by programmer)
  5. STACK (managed automatically by compiler)

frames

This is the state/context for a single procedure

  • local variables
  • function arguments
  • return address (pointer to caller)
  • saved register context
  • stack frame = %esp - %ebp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment