Skip to content
Registersx86-64

RBP Register

RBP is the x86-64 frame pointer: what [rbp-8] and [rbp+16] mean, why optimized code drops the frame, and how leave; ret turns it into a stack pivot.

RBP is the frame pointer, when the compiler bothers to keep one. In unoptimized code it sits still for the whole function and everything on the stack is addressed relative to it. In optimized code it is usually just a seventh callee-saved register that happens to have a historical name.

The frame it anchors

A function compiled with a frame pointer opens and closes like this:

asm
push rbp            ; save the caller's frame pointer
mov  rbp, rsp       ; this function's frame starts here
sub  rsp, 0x20      ; room for locals
...
leave               ; mov rsp, rbp / pop rbp
ret

After that prologue the layout is fixed, and it is worth knowing by heart:

AddressContents
[rbp+0x10] and upstack arguments (the 7th onwards on System V)
[rbp+0x8]return address
[rbp]the caller's saved RBP
[rbp-0x8] and downlocals and spilled registers

So a negative offset from RBP is a local and a positive one belongs to the caller. On Windows the picture shifts: the caller's 32 bytes of shadow space sit at [rbp+0x10] through [rbp+0x28], and the fifth argument is at [rbp+0x30]. Unoptimized MSVC code spills rcx, rdx, r8 and r9 into those home slots first thing, which is why debug builds are so easy to read.

Each saved RBP points at the previous frame's saved RBP, so the frames form a linked list. That chain is the cheapest possible stack unwinder, and it is what perf, eBPF profilers and most hand-written stack walkers follow.

When there is no frame

GCC and Clang omit the frame pointer on x86-64 at -O1 and above. Locals are then addressed from RSP, and RBP is free for general use. Seeing rbp used as a loop counter or holding a this pointer is normal in release builds, and it does not mean the disassembly is broken.

Two things have made frames more common again. Fedora 38 and Ubuntu 24.04 both started building their packages with -fno-omit-frame-pointer so that profilers can walk stacks cheaply. And MSVC, which normally addresses everything from RSP, sets up a frame register whenever a function calls alloca, often pointing it into the middle of the frame instead of at the saved value. In that case the offsets above do not apply; read the unwind info (UNWIND_INFO with a frame register and offset) to see where it points.

Debuggers do not rely on the chain. GDB and LLDB unwind from .eh_frame call-frame information, and WinDbg from .pdata, which is why backtraces still work in frameless code and stop working in shellcode and hand-written stubs.

Encoding quirk

[rbp] cannot be encoded without a displacement. The ModRM combination that would mean "rbp, no displacement" was reassigned to RIP-relative addressing, so assemblers emit [rbp+0] with a zero byte:

asm
48 8b 45 00    mov rax, [rbp]      ; note the trailing 00
48 8b 03       mov rax, [rbx]      ; one byte shorter

R13 has the same limitation, since it shares the low three encoding bits.

Sub-registers

EBP is the low 32 bits, BP the low 16 and BPL the low 8. BPL only exists with a REX prefix; without one the same encoding means CH. Writing EBP zeroes the upper half of RBP.

Reverse-engineering notes

RBP is callee-saved in both the System V and Microsoft ABIs. If a function uses it for anything, it must push it first.

leave; ret is a stack pivot waiting to be used. An overflow that overwrites the saved RBP controls RSP one leave later, which is the whole trick behind frame-pointer overwrites and a common way to move a ROP chain to a buffer you control.

Anti-debug and unpacking stubs sometimes use RBP as a base for position-independent data (call $+5; pop rbp; sub rbp, <const>), then address everything as [rbp+offset]. If the decompiler shows a wall of nonsense locals in a packer stub, that is usually what is going on.

Related: RSP, the stack, calling conventions, and the full general-purpose register map.