On compiling. (Was a way off topic subject)

Chuck Guzis cclist at sydex.com
Fri Jun 25 17:04:28 CDT 2021

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_JSR_
>> 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

Interesting status returns can be implemented by adjusting the return
address on the stack in sort of a "reverse" computed goto; e.g.

      add [stack top], status*jump instruction size

...calling code...
       call sub_entry
       jmp  status_0
       jmp  status_1
       jmp  status_2

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.


More information about the cctalk mailing list