Structures#

There are no structs in assembly, only contiguous bytes addressed by offsets. Higher-level languages compile their data layouts to sequences of mov, lea, and effective-address arithmetic that you can read directly.

Memory layout#

Section

Contents

.text

Executable instructions (read + execute).

.rodata

Read-only data (string literals, jump tables).

.data

Initialised mutable globals.

.bss

Uninitialised globals (zero-filled by the loader).

heap

Dynamic allocations (malloc / brk / mmap).

stack

LIFO; one frame per function call; grows downward on x86.

Stack frames (System V x86-64)#

high addr    +--------------------+              |  caller's frame    |              +--------------------+              |  return address    |  <- pushed by CALL              +--------------------+              |  saved rbp         |  <- push rbp; mov rbp, rsp      rbp --> +--------------------+              |  local variables   |              |  (callee-saved)    |              +--------------------+      rsp --> |  outgoing args     | low addr     +--------------------+
        flowchart LR
    A["caller's frame"]
    B["return address (pushed by CALL)"]
    C["saved rbp"]
    D["local variables / callee-saved"]
    E["outgoing args (rsp)"]
    A --> B --> C --> D --> E
    

Records and arrays#

A C struct becomes a base pointer plus offset:

; struct point { int32 x; int32 y; };
mov  eax, [rdi + 0]      ; load x
mov  edx, [rdi + 4]      ; load y

; array of 8-byte elements: lea rax, [rbx + rcx*8]
lea  rax, [rbx + rcx*8]
mov  rdx, [rax]

References#