I have my stack working. It takes a lot of lines to do a pop/push, but that's the nature of a RISC or OISC. I thought about having two dedicated registers for the stack pointer, but I really don't want to increase the hardware complexity when I can do it in software. I assigned the stack pointer to memory locations 0xFFFE and 0xFFFF. Since it contains a memory location, it needs two bytes.
It initially points to 0xFFFD. So it points to the next available memory location (empty stack style). Then the stack grows down. Pushing to the stack will write the byte first, then increase the stack pointer. Popping from the stack will decrease the stack pointer first, then read the byte there.
Ok, I have the first test of the routine hardwired to return to a specific address, so I need to update it to grab the Program Counter and then add an offset. The offset changes as I refine the push function, but I can handle that.
I found that my string output function would be really handy if I could push a memory address onto the stack which contains the pointer to the string, and then call the function (pushing the return address on the stack). So my string function would grab the string pointer off the stack, and at the end pop the return address off the stack.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.