Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
cpu [2022/08/20 22:01] – remove 1.2-specific parts, other simplifications and corrections simercpu [2022/11/12 14: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, the stack grows downwards (PUSH decrements SP) and the stack pointer points to the first empty space below the stack.
 +
 +As a result, the typical organization of the stack in VTech code is:
 +
 +^Address^ Contents       ^ Notes                              ^
 +| 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't move and can be used to access both local variables and function parameters.
 +
 +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 ====
  
Line 243: Line 261:
 |%%MR = [Rd] x [Rs],us,n %%|%%MAC.US [Rd], [Rs], N %%|Multiply-accumulate two sets of N values pointed by Rd (unsigned values) and Rs (signed values) | :::          | |%%MR = [Rd] x [Rs],us,n %%|%%MAC.US [Rd], [Rs], N %%|Multiply-accumulate two sets of N values pointed by Rd (unsigned values) and Rs (signed values) | :::          |
  
-Multiply-accumulate operations do the computation with 32-bit precision with the result is stored in MR. +Multiply-accumulate operations do the computation with 32-bit precision with the result is stored in MR. The Rd and Rs pointers will automatically be incremented by N
 +The values of the array pointed to by the Rd array will each be moved one index forward when the FIR_MOV setting is enabled, see the FIR_MOV section for details.
 ==== FIR_MOV ==== ==== FIR_MOV ====
  
cpu.1661025674.txt.gz · Last modified: 2022/08/20 22:01 by simer
CC Attribution 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0