Update sketch to suggest use of `*ADDR`
This commit is contained in:
parent
4e01a0943c
commit
8f9f50e28c
|
|
@ -1,5 +1,10 @@
|
||||||
;; sketching around subroutines with return stack
|
;; sketching around subroutines with return stack
|
||||||
|
|
||||||
|
; I think the sketching below contains some useful ideas,
|
||||||
|
; but the new `*ADDR` assembly op should make this a whole lot simpler
|
||||||
|
|
||||||
|
; sketches follow ..........
|
||||||
|
|
||||||
; jump table
|
; jump table
|
||||||
; ----------
|
; ----------
|
||||||
; each function has a label
|
; each function has a label
|
||||||
|
|
@ -10,53 +15,59 @@
|
||||||
; then when the subroutine ends, it jumps here
|
; then when the subroutine ends, it jumps here
|
||||||
; where that number gets mapped back onto the function's label
|
; where that number gets mapped back onto the function's label
|
||||||
|
|
||||||
lda $1
|
=*reentryPoint
|
||||||
|
=routine1 $1
|
||||||
|
|
||||||
|
lda =routine1
|
||||||
sto $19 ; contains ID # for the next fn to jump to
|
sto $19 ; contains ID # for the next fn to jump to
|
||||||
|
|
||||||
@jump_table
|
@jump_table
|
||||||
hop $1
|
hop $1
|
||||||
jmp @jt2
|
jmp @jt2
|
||||||
jmp @example_computation
|
jmp @example_computation
|
||||||
@jt2
|
|
||||||
hop $2
|
@jt2
|
||||||
|
hop $2
|
||||||
; jmp @jt3
|
; jmp @jt3
|
||||||
nop
|
nop
|
||||||
; etc …
|
; etc …
|
||||||
jmp @end
|
|
||||||
|
jmp @end
|
||||||
|
|
||||||
@example_computation
|
@example_computation
|
||||||
lda 5
|
lda 5
|
||||||
sto $20
|
sto $20
|
||||||
lda 3
|
lda 3
|
||||||
sto $21
|
sto $21
|
||||||
; $19 still has the # for this routine
|
; $19 still has the # for this routine
|
||||||
; but let’s pretend it doesn’t and demonstrate updating it
|
; but let’s pretend it doesn’t and demonstrate updating it
|
||||||
lda $1
|
lda $1
|
||||||
sto $19
|
sto $19
|
||||||
jmp @greater?
|
jmp @greater?
|
||||||
|
|
||||||
; call with numbers to test in $20 and $21
|
; call with numbers to test in $20 and $21
|
||||||
; result is stored in acc
|
; result is stored in acc
|
||||||
@greater?
|
@greater?
|
||||||
; lda ($20)
|
; lda ($20)
|
||||||
; sub ($21)
|
; sub ($21)
|
||||||
; todo…
|
; todo…
|
||||||
; wouldn’t it be great to have a “hop if neg” op…
|
; wouldn’t it be great to have a “hop if neg” op…
|
||||||
; do we have to just subtract numbers until we get 0?
|
; do we have to just subtract numbers until we get 0?
|
||||||
|
|
||||||
; no!
|
; no!
|
||||||
; here’s an approach that’s at least better than that
|
; here’s an approach that’s at least better than that
|
||||||
lda ($21)
|
lda ($21)
|
||||||
sto $22 ; stash
|
sto $22 ; stash
|
||||||
@loop
|
@loop
|
||||||
lda ($21)
|
lda ($21)
|
||||||
sub $1
|
sub $1
|
||||||
sto $22 ; stash
|
sto $22 ; stash
|
||||||
sub ($20)
|
sub ($20)
|
||||||
hop $0
|
hop $0
|
||||||
jmp @loop
|
jmp @loop
|
||||||
sto $1
|
sto $1
|
||||||
jmp $jmp_table
|
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
|
; 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
|
@end
|
||||||
|
END
|
||||||
Loading…
Reference in New Issue