The new microcode version, with new instructions, is working now !
We now have STACK instructions:
PUSH Z ; move a 16-bit value from Z-page to stack POP Z ; move a 16-bit value from stack to Z-page CALL label ; push the return address on stack and jump to 16-bit label ; 4-byte instruction: opcode, unused, label-lsb, label-msb RET ; load the pc from stack (equivalent to POP PC)
The stack is similar to the 6502 stack, it occupies locations 0100-01FF. There is a single-byte
stack pointer at location 0 in RAM. The stack grows downwards. All items on stack are 16-bit.
Note that it would be possible to change the microcode to have a separate stack for return addresses, this would enable a FORTH-style of programming.
Another new instruction is the BYTE-COMPARE instruction:
CMPB A,Z ; compare byte in accumulator with byte in zpage ; result A=0x00 when both are equal, A=0x80 when not equal
This works together with the conditional branches BRM and BRP. To make programming easier, the BRM and BRP instructions also have another name from now on: BEQ and BNE, that do exactly what you would expect after a compare instruction:
BEQ label ; branch if bytes were equal BNE label ; branch if bytes were not equal
The conditional branches BRM and BRP were originally defined to assist in loop counting. A loop counter could count backwards from a certain value (up to 127). When the count changes from 00 to FF, this FF value can be detected by a BRM (branch if minus) or BRP (branch if positive) instruction.
Back to the byte-compare instruction. How is it possible that it compares two bytes, while there is no ALU or byte-compare chip that can do this function ?
Suppose the two values to compare are XX and YY (hex). The processor needs the reserved RAM region 0x0200-0x02FF for this function.
- It writes 0x80 to 0x02XX
- It writes 0x00 to 0x02YY
- The result is read from 0x02XX.
Ii is easy to see that the result will be 0x80 because that was written to 0x02XX. But if YY is the same as XX, the value at 0x02XX is overwritten by 0x00, so the result is 0x00 when both values are equal ! That is how it works !