We made an update, adding a link register and three instructions, which give us subroutine capability. There's still no stack!
The cost of this update, in fitting in the CPLD, was one address bit, so we move down from a 12 bit address space to 11 bits.
JSR stores the current PC in the link register and the accumulator - the PC is 11 bits, the accumulator only 8, so we needed a 3 bit link register. RTS copies the link and accumulator into the PC. That's almost enough, but to save a return address we need access to the link register, so LXA exchanges the link register and the accumulator.
In fact here's the spec on the subject:
- Subroutine call and returns are handled by the LXA, JSR and RTS instructions. When a JSR instruction is issued the upper 3 bits of the PC are placed into a link register and the lower 8 bits are stored in the accumulator. On entering the subroutine the accumulator value should be saved and then using the LXA instruction the link register bits can be moved to the accumulator and saved also. On leaving a subroutine the return address needs to be retrieved by the reverse of this process. First get the upper return address bits into the accumulator, then transfer them to the link register using LXA and finally get the lower return address bits into the accumulator. Executing the RTS will now set the PC to the 11 bit value made by concatenating link register with accumulator.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.