Why oh why can't we use the 65816 stack as the Data Stack?
Posted: Wed Feb 15, 2017 10:41 am
For weeks, nay, months now I have been trying to figure out a sane way to design a Forth for the 65816 that uses the MPU's stack not as the Return Stack (RS), but as the Data Stack (DS). Combined with using A (or Y) as Top of Stack, this would make a lot of things so much easier: CONSTANT would not need a subroutine jump to DOCONST, but a simple PEA (phe.# for me) instruction, DROP becomes PLA (or PLY), DUP becomes PHA, etc. But I can't figure out a workable way to deal with the RS. This is frustrating.
My least horrible solution so far: You could keep one stack pointer in X and one in A so that (say) TXS would come before a DS access and TCS before a RS access. So each word in a STC design would include But that's an additional 4 bytes and 8 cycles for each word, and you're using two registers. Another idea was dealing with the RS by hand with a combination of X as the RS pointer and JMP (addr, X) instructions, but workable this is not. You could limit the stacks to 256 bytes each, keep one pointer in A and the other in B, and then attempt some trickery with XBA and TCS for which ever one you need, but the overhead gets bad as well. All of these would make wickedly fast compiled Forth words, because you could strip out the housekeeping stuff rather easily. However, the penalty for anything interactive and for high-level words would be brutal.
I can't be the first one to bang his head against this wall. Is the consensus that it really isn't worth the effort, or am I missing something?
My least horrible solution so far: You could keep one stack pointer in X and one in A so that (say) TXS would come before a DS access and TCS before a RS access. So each word in a STC design would include
Code: Select all
TSC ; save RSP
TXS ; get DSP
( ... actual word code ...)
TSX ; save DSP
TCS ; restore RSP
RTSI can't be the first one to bang his head against this wall. Is the consensus that it really isn't worth the effort, or am I missing something?