LOGBOOK

HELP

Quiz Entry - updated: 2026.07.06

How do you recognize a function prologue and epilogue in assembly?

The prologue saves callee-saved registers (push) and allocates locals (sub $N, %rsp); the epilogue reverses both before ret.

Prologue: push callee-saved regs then sub $N,%rsp for locals. Epilogue reverses it: add $N,%rsp, pop the regs in reverse order, then ret (or leave;ret with a frame pointer).

* Prologue pushes callee-saved registers and subtracts %rsp for locals; the epilogue exactly reverses both (add %rsp, pop in reverse) before ret. leave replaces the two-step teardown when a frame pointer is used. *

Typical prologue:

my_func:
    push %rbp
    push %rbx
    sub  $0x18, %rsp

Typical epilogue:

    add  $0x18, %rsp
    pop  %rbx
    pop  %rbp
    ret

What each part does:

  • push %rbp / push %rbx — save callee-saved registers the function will use
  • sub $0x18, %rsp — allocate 24 bytes for local variables
  • Epilogue reverses everything in opposite order

Minimal function (uses no callee-saved registers, no locals):

my_func:
    # just does work with caller-saved registers
    ret

With frame pointer (when compiled with -fno-omit-frame-pointer):

    push %rbp
    mov  %rsp, %rbp
    ...
    leave
    ret

leave = mov %rbp, %rsp + pop %rbp

Go deeper:

From Quiz: REVE1 / Assembly Patterns & GDB | Updated: Jul 06, 2026