Sim8 has four "user accessible" registers, and four registers that are use internally by the CPU but can't be accessed by user programs.
The four user registers are:
AC (Accumulator)
This is the target of most of the logical and arithmetic instructions.
IX (Index Register)
When an instruction uses "indirect" addressing, the index register holds the memory address of the operand for that instruction.
SP (Stack Pointer)
Give the location of the "stack" in memory. When a "CALL" instruction are encountered, the computer's registers are pushed on the stack before the the subroutine is executed. The "RET" instruction pops the registers back off the stack before returning to the calling program.
With only 256 bytes of memory, you need to be careful that your stack doesn't grow down and over-run your program or data!
ST (Status Register)
The SR contains shows the result of various operations and errors that might be encountered during the execution of a program.
bit0: Underflow bit1: Overflow bit2: Divide by zero bit3: bit4: Illegal instruction (user program will only see zero, since cpu will halt) bit5: Processor Halted (user program will only see zero) bit6: Machine cycle count (user programs only see zero) bit7: Machine cycle count (user programs only see zero) After an add or multiply operation, bits 0 and 1 are interpreted like this: 00: no carry, the full result is in the accumulator 01: (can't happen) 10: there was an overflow or carry After a subtract or divide operation, bits 0 and 1 are interpreted like this: 00: no borrow, the full result is in the accumulator 01: underflow or borrow 10: (can't happen) After a compare operation, bits 0 and 1 are interpreted like this: 00: accumulator was equal too compared value 01: accumulator was less than compared value 10: accumulator was greater than compared value
The four internal registers are:
PC (Program Counter)
The program counter contains the memory address of the next instruction to be executed.
I0 (Instruction word 0)
During the initial instruction fetch cycle (which is the first cycle of every Sim8 instruction) the I0 register is loaded with the first byte of the instruction.
I1 (Instruction word 1)
For two byte instructions, I1 is loaded with the 2nd byte of the instruction during the second fetch cycle.
OP (Operand Register)
For instructions that use "memory" addressing, the operand register is loaded with the required operand (typically during the third fetch cycle.)