# Stack (ivss) The **stack** stores saved register values and return addresses in memory. ivss uses `%sp`, an alias for `%r14`, and grows the stack toward lower addresses: ```asm ld $42, %r1 push %r1 # sp -= 4; memory[sp] = 42 ld $0, %r1 pop %r2 # r2 = 42; sp += 4 ``` Each push reserves one four-byte word before writing it. A pop reads the top word and then releases that space. The emulator initializes `%sp` to `0x80000000`, so this balanced pair returns it to that address. For a pushed value $v$, the state transition is: $$ SP'=SP-4,\qquad M_{32}[SP']=v $$ Here $M_{32}$ denotes a 32-bit memory access. The last value pushed is the first one popped, so multiple saved registers must be restored in reverse order. A call also pushes its return address, and `ret` retrieves it. Interrupt handling saves additional state. Assembly routines must balance their own pushes and pops so that return instructions find the expected values rather than an unrelated saved register. Source: [asembler.c](https://github.com/yanevskiv/ivss/blob/main/src/asembler.c), [math.s](https://github.com/yanevskiv/ivss/blob/main/test/nivo-a/math.s).