James Newton says:
Warning: Assembly code and bad memory
1000 years ago, when I was 17, I wrote a FORTH for the Z80 on a Trash 80. It was unique for the time, because it used the machine language RET as NEXT for asm words. e.g. the machine stack pointed NOT at the data stack or return stack but at the list of word addresses being executed; the thread. That meant that asm words could be strung together even faster than a standard asm program because there was no asm CALL... the RET was both the return from the current asm word AND the call to the next one. The address of the data and return stacks were kept elsewhere... one of the other registers or a memory location (I don't remember, code is long lost). I think it was IX and IY. Every non-asm word had to start with an asm call to a routine that saved SP to the return stack pointer, set the SP to the value on the stack and RET. If I remember, that's called THREAD? Then at the end, the last address was to an asm word that pulled the return stack TOS back into SP and RET. I seem to remember that is called NEXT. So for asm words, NEXT is RET and for higher level words, NEXT was a few asm instructions.
Advantages: /screaming/ fast low level words, no slower high level words.
Disadvantages: low level words couldn't really use the stack, because they would overwrite a thread. Of course, you could save and restore SP... but I seem to remember doing most manipulation of the stack with other registers. e.g. LD (IX+0),SP; INC IX; INC IX; Or maybe it was DEC, I don't remember.
And the big disadvantage: NO INTERRUPTS during asm words! LOL. Can't save PC to TOS because it would over write a thread. I got around that somewhat by adding an EI (enable interrupts) in the NEXT code while the SP was pointed at the return stack, doing a NOP and then DI. LOOP also had that in it because it was asm.
|file: /Techref/language/forths.htm, 5KB, , updated: 2018/11/8 21:36, local time: 2019/3/21 18:27,
|©2019 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://techref.massmind.org/techref/language/forths.htm"> the FORTH programming language </A>
|Did you find what you needed?|
Welcome to massmind.org!
Welcome to techref.massmind.org!