Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
cpu [2022/08/20 20:12] – [Multiplication] simer | cpu [2022/11/12 13:57] (current) – [Registers] pulkomandy | ||
---|---|---|---|
Line 27: | Line 27: | ||
The BP register has a special addressing mode with a 6-bit immediate offset. It is usually (for example by unsp IDE C compiler) used as a frame pointer, to access a function local variables efficiently. But it can also be used as a normal register if needed. | The BP register has a special addressing mode with a 6-bit immediate offset. It is usually (for example by unsp IDE C compiler) used as a frame pointer, to access a function local variables efficiently. But it can also be used as a normal register if needed. | ||
+ | SP is generally used as a stack pointer but can be used for other things occasionally. When using the PUSH and POP instructions, | ||
+ | |||
+ | As a result, the typical organization of the stack in VTech code is: | ||
+ | |||
+ | ^Address^ Contents | ||
+ | | NNNF | Parameter 0 | Pushed by caller | ||
+ | | NNNE | Parameter 1 | | | ||
+ | | NNND | PC (from CALL) | Saved by CALL | | ||
+ | | NNNC | SR (from CALL) | Saved by CALL | | ||
+ | | NNNB | R4 | Saved by PUSH in function prelude | ||
+ | | NNNA | R3 | (and more registers as needed) | ||
+ | | NNN9 | Local variable | Space allocated by decrementing SP | | ||
+ | | NNN8 | Local variable | <- BP points here | | ||
+ | | NNN7 | Empty | <- SP points here | | ||
+ | |||
+ | The SP can move when calling other functions, interrupts, ... or when saving registers inside the function code. But BP doesn' | ||
+ | |||
+ | The parameters are usually removed by the caller (by incrementing SP). It would also be possible to use a POP including SR and PC to return from the function while clearing parameters, but this requires loading them into registers, which is not always desirable since registers are rather used for return values. | ||
==== Status Register ==== | ==== Status Register ==== | ||