Skip to content

Instantly share code, notes, and snippets.

@rosswd
Last active April 13, 2023 17:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosswd/54a880d94330b5a22abe575b6d9f33d0 to your computer and use it in GitHub Desktop.
Save rosswd/54a880d94330b5a22abe575b6d9f33d0 to your computer and use it in GitHub Desktop.
The stack, heap, registers and instructions

Stack, Heap, Registers and Instructions

  1. Stack (push, pop, stack pointer, stack frame pointer)
  2. Heap (malloc, calloc, global, static)
  3. Registers (addresses, values)
  4. Instructions (mov, add, jmp, jne)

The Stack (LIFO)

  • push adds an element to the top of the stack
  • pop removes the top element from the stack
  • each element has a stack address
  • the stack grows towards lower memory addresses (windows)
    • elements near the top of the stack have a lower address
    • elements near the bottom of the stack have a higher address
  • whenever a function is called that function is set up with a stack frame
  • all the local variables of the function are stored in that function's stack frame
    • ebp register, aka the base pointer, contains the address for the current stack frame
    • esp register, aka the stack pointer, points to the top element of the current stack frame

The Heap

TBC

Registers

  • 6 General Purpose Registers (eax ebx ecx edx esi edi)
  • 3 Reserved Registers (ebp esp eip)
    • eip - instruction pointer
    • esp - stack pointer
    • ebp - (frame) base pointer

Instructions

  • mov, push, pop
  • add, sub
  • cmp
  • jmp
  • nop
  • call
  • inc
  • ret
  • lea
  • je, jne, jle, jg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment