Skip to content

CPU Registers

  • https://www.youtube.com/watch?v=ySOm8CdpnXI&ab_channel=PaladinGroup%2CLLC
  • https://www.youtube.com/watch?v=_D8eLCmlrS8&list=PLdVIvW2RPTRxNdJeBZRcdt1JQJlmQlQMU&ab_channel=flipthebit
  • https://youtu.be/1S0aBV-Waeo
  • registers are the essential components of a CPU.
  • most registers offer a small amount of storage space where data can be temporarily stored.
  • Register types:
    • General registers IMPORTANT
      • data, pointer, index
    • Control registers
    • Segment registers

Stack Frames

  • stack starts from a high address and grows down to a lower memory address as values are added.
  • the base pointer points to the beginning of the stack.
  • the stack pointer points to the top of the stack.
  • As the stack grows, it is logically divided into regions called Stack Frames,
    • which allocate the required memory in the stack for the corresponding function.
  • A stack frame defines a frame of data with the beginning (EBP) and the end (ESP) that is pushed onto the stack when a function is called.

Prologue

  • when a new function is called.
  • the previous ebp value is pushed on the stack
  • the old esp value is written to ebp
  • some value is subtracted from the esp to push it down
  • this will create new values for ebp and esp which will be the stack frame for this function.

Epilogue

  • write current ebp value to esp
  • pop ebp to bring it to old ebp
  • this will return us to the main() stack frame.

  • Compiling in 64-bit
    gcc bow.c -o bow64 -fno-stack-protector -z execstack -m64
    student@nix-bow:~$ file bow64 | tr "," "\n"