Structs

Contents

Structs#

A struct in assembly is just a layout: an offset for each field inside a contiguous block. The operator hand-tracks offsets or uses NASM’s struc directive.

Declare a struct layout.

; struct user { uint64_t id; char name[16]; uint32_t age; };

struc User
    .id     resq 1              ; offset 0
    .name   resb 16             ; offset 8
    .age    resd 1              ; offset 24
endstruc

Use the named offsets at the call site.

mov     rax, qword [rdi + User.id]
mov     dword [rdi + User.age], 30

The C compiler’s offsetof macro tells the operator the authoritative offsets when interop matters; pin layouts with __attribute__((packed)) on the C side if needed.

References#