3 ms·
A similar "trick" was used on some 8-bit home computers for passing (optionally variable-length) data to operating system calls. For instance on the KC85/2..4
by flohofwoe 3y ago
A similar "trick" was used on some 8-bit home computers for passing (optionally variable-length) data to operating system calls.
For instance on the KC85/2..4 operating system (CAOS) the equivalent of "puts()" expects the "syscall index" and zero-terminated text to print after the call instruction, e.g.:
CALL 0F003H ; call into generic "syscall" entry
DEFB 23H ; "syscall" identifier
DEFM 'HELLO WORLD!'
DEFW 0D0AH ; newline
DEFB 00 ; end of text
NOP ; execution continues here
The syscall dispatcher would pop the return address from the stack and that way discover the data. Before the syscall returns, a modified return address which points to the first byte after the data is pushed back on the stack.
Only downside of this approach was that disassemblers would get terribly confused, unless they had specific knowledge about this CAOS peculiarity.
- PinguTS 3y agoOh, yeah, KC85. We had them in school, when I was in my early teens.
- warpspin 3y agoYes. C64 GEOS also used this a lot. They used to call it „inline calls“: https://archive.org/details/The_Official_GEOS_Programmers_Reference_Guide/page/n37/mode/2up https://archive.org/details/The_Official_GEOS_Programmers_Re...
- n_plus_1_acc 3y agoThe TI 83 family of calculators with a Z80 also use this.
- jsymolon 3y agoApple II, DOS and PRODOS calls do that too. https://prodos8.com/docs/techref/calls-to-the-mli/ https://prodos8.com/docs/techref/calls-to-the-mli/
- tenebrisalietum 3y agoThe C128 had a KERNAL routine called PRIMM that did that.
- deleted 3y ago[deleted]
- cancerhacker 3y agoClassic Mac used this for some toolbox traps as well. Most apps used a jump table at some offset from the A5 register, which looked like: addr: _LoadSeg dc.w segmentNumber dc.w segmentOffset The _LoadSeg trap would ensure that 'CODE'(segmentNumber) was loaded from disk and then modify the jump code @addr to become an absolute JMP (0x4ef9 + 32 bits) and then set the PC back to @addr and return from the trap. There was also an _UnloadSeg mechanism that would reverse this!