1.3 KiB
1.3 KiB
Dev notes — 2023-08-12
Call stack
Brainstorming/sketching around subroutines with a return stack...
; need an instruction for IP → A i guess?
; ideally…
; but a jump table would work
; put that at beginning of the code
; then store numbers for subroutine labels in a designated memory slot
lda $1
sto $19 ; contains ID # for the next fn to jump to
@jump_table
hop $1
jmp @jt2
jmp @example_computation
@jt2
hop $2
; jmp @jt3
nop
; etc …
jmp @end
@example_computation
lda 5
sto $20
lda 3
sto $21
; $19 still has the # for this routine
; but let’s pretend it doesn’t and demonstrate updating it
lda $1
sto $19
jmp @greater?
; call with numbers to test in $20 and $21
; result is stored in acc
@greater?
; lda ($20)
; sub ($21)
; todo…
; wouldn’t it be great to have a “hop if neg” op…
; do we have to just subtract numbers until we get 0?
; no!
; here’s an approach that’s at least better than that
lda ($21)
sto $22 ; stash
@loop
lda ($21)
sub $1
sto $22 ; stash
sub ($20)
hop $0
jmp @loop
sto $1
jmp $jmp_table
; ok this isn’t quite it… we also need to chexk if we hit 0 by just deceementinf and if so retuen 0
jmp @jump_table