When a function is called, it have parameters, a return value and some variables.
Here is a map of how they are stored in the stack:
┌─────────────────┐ │ Caller frame │ ├─────────────────┤ │ Parameters │ ← PUSHREL/POPREL access ├─────────────────┤ │ Return Value │ ← PUSHREL/POPREL access ├─────────────────┤ ← SP │ Local vars │ ← PUSHREL/POPREL access ├─────────────────┤ │ Temporaries │ ← Stack top └─────────────────┘
Local variables: Accessed via SP-relative offsets - ‘PUSHREL 0’: First local - ‘PUSHREL 8’: Second local (8-byte offset) - ‘POPREL N’: Store to local at offset N
Return value and paramers: Accessed via SP-relative offsets - ‘PUSHREL -8’: Return value - ‘PUSHREL -16’: First parameter - ‘PUSHREL -24’: Second parameter