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 |
|---|---|
|
Executable instructions (read + execute). |
|
Read-only data (string literals, jump tables). |
|
Initialised mutable globals. |
|
Uninitialised globals (zero-filled by the loader). |
heap |
Dynamic allocations ( |
stack |
LIFO; one frame per function call; grows downward on x86. |
Stack frames (System V x86-64)#
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#
Data Structures, the C side of the same layouts.