FIG Forth's NEXT function confuses me slightly
Posted: Fri Aug 05, 2022 5:56 pm
In the Programming sub-forum I built a threaded interpreter that executes the BF language. I modeled my threaded interpreter on Forth and in the process I learned more about Forth itself. The next function is where a lot of cycles are spent and it's worth optimization for any threaded implementation. So I decided to re-read FIG Forth's next function to see if I could pick up any tips. But instead theĀ code left me wondering if I'm missing something.
Here's theĀ original with my question afterwards:
Initially I found it confusing to use (IP),Y indexed addressing to load the threaded code address, but then I realized that indirect addressing without an index register was added for the 65c02. They also used adc #2 rather than two word increments because it's about six cycles faster (21 vs 30). Although the ldy #2 and DEY negate that advantage if you optimized for the 65c02.
So far so good.
But what I don't understand is the jmp to jmp where the code wrote the absolute address. Why wouldn't they use a jmp (w) since W isn't on a page boundary?
Here's theĀ original with my question afterwards:
Code: Select all
NEXT: ldy #1
lda (IP),Y ; Fetch code field address pointed
sta W+1 ; to by IP.
dey
lda (IP),Y
sta W
`TraceNext ; Macro determines what (if anything) this does
clc ; Increment IP by two.
lda IP
adc #2
sta IP
bcc L54
inc IP+1
L54: jmp W-1 ; Jump to an indirect jump (W) which
; vectors to code pointed to by a code
; field.
So far so good.
But what I don't understand is the jmp to jmp where the code wrote the absolute address. Why wouldn't they use a jmp (w) since W isn't on a page boundary?