On 6/25/21 3:31 AM, Kelly Fergason via cctalk wrote:
> On Jun 25, 2021, at 4:54 AM, Gordon Henderson via
cctalk <cctalk at classiccmp.org> wrote:
>
>
http://www.6502.org/source/interpreters/sweet16.htm#When_is_an_RTS_really_a…
>
> I initialiy used this "trick" in my own little bytecode VM but it's
somewhat slower than some other methods, but as usual the trade-off is code-size vs.
speed...
This "trick" can be performed on nearly any microprocessor with a stack
that keeps return addresses on said stack--and permits a program to push
data onto the stack. Certainly x80 and x86 CPUs, where it isn't that
uncommon.
Interesting status returns can be implemented by adjusting the return
address on the stack in sort of a "reverse" computed goto; e.g.
sub_entry:....
add [stack top], status*jump instruction size
return
...calling code...
call sub_entry
jmp status_0
jmp status_1
jmp status_2
..etc.
Which saves the caller from having to perform multiple compares (or a
computed GOTO) on the status return.
On lower PIC microcontrollers, there is no way for a program to access
code space (i.e. Harvard architecture). Static lookup tables represent
a concept requiring some thought. Low PIC code memory uses 13 bit
words, while data memory uses 8. Fortunately, there is an opcode,
RETLW, that is "return from subroutine with 8 bit value in the W
register". So one codes a table of RETLW xx instructions and performs
an indexed call into it.
--Chuck