From Just a bit RISC
Jump to: navigation, search


Register Description

Register Purpose
r0 Dummy register = 0
r1 General Purpose
r2 General Purpose
r3 General Purpose
r4 General Purpose
r5 General Purpose
pc (r6) Program Counter
sp (r7) Stack Pointer

The datapath contains 8 registers available to the programmer. r1 to r5 are fully general purpose and be accessed by any instruction that takes a register as an argument.

The register r0 always contains the value ‘0’ when read and if assigned the value stored will not change. Assigning a value to r0 enables the programmer to set the flags without modifying values stored in any registers.

Register pc (or r6) always stores the value of the program counter. The program counter increments before every instruction including relative jumps, this must be considered when determining relative jump targets as there will be an offset of ‘1’.

The register sp (or r7) always contains the current value of the stack pointer. The stack pointer contains ‘0’ by default and so must be initialised by the programmer. The stack pointer will be automatically modified accordingly by the { PUSH} and { POP} commands. The stack implementation is that of a “full descending” stack, the stack pointer therefore provides a pointer to the topmost element of the stack. On a { PUSH} command the stack pointer is pre-decremented and on a { POP} instruction the stack pointer is post-incremented.

The program counter and stack pointer can also be used as general purpose registers. This allows the programmer to write to and read from both of these registers using the same syntax and instructions as with r1 to r5. If an interrupt occurs the program counter will be set to a value of ‘1’, which is a hard-wired value and explained further in Section {s:Int}.

The immediate register will automatically be loaded with the correct value if the current instruction makes use of an immediate value. The appropriate sign extension will be performed according to the opcode. If the instruction uses a 16-bit immediate the register will be loaded with the immediate value and no sign extension will be performed.

The instruction register will contain the instruction that has been loaded from the memory location pointed to by the current value of the program counter. The instruction register is not accessible by the programmer and can only be controlled through the use of the program counter.