aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/msp430/words/do-do.asm
diff options
context:
space:
mode:
Diffstat (limited to 'amforth-6.5/msp430/words/do-do.asm')
-rw-r--r--amforth-6.5/msp430/words/do-do.asm25
1 files changed, 25 insertions, 0 deletions
diff --git a/amforth-6.5/msp430/words/do-do.asm b/amforth-6.5/msp430/words/do-do.asm
new file mode 100644
index 0000000..cdb0a81
--- /dev/null
+++ b/amforth-6.5/msp430/words/do-do.asm
@@ -0,0 +1,25 @@
+;Z (do) n1|u1 n2|u2 -- R: -- sys1 sys2
+;Z run-time code for DO
+; '83 and ANSI standard loops terminate when the boundary of
+; limit-1 and limit is crossed, in either direction. This can
+; be conveniently implemented by making the limit 8000h, so that
+; arithmetic overflow logic can detect crossing. I learned this
+; trick from Laxen & Perry F83.
+; fudge factor = 8000h-limit, to be added to the start value.
+; ; CODEHEADER(xdo,4,"(do)")
+; DW link
+; DB 0FFh ; not immediate
+;.set link = $
+; DB 4,"(do)"
+; .align 16
+XT_DODO:
+xdo: DW $+2
+ SUB #4,RSP ; push old loop values on return stack
+ MOV LIMIT,2(RSP)
+ MOV INDEX,0(RSP)
+ MOV #8000h,LIMIT ; compute 8000h-limit "fudge factor"
+ SUB @PSP+,LIMIT
+ MOV TOS,INDEX ; loop ctr = index+fudge
+ ADD LIMIT,INDEX
+ MOV @PSP+,TOS ; pop new TOS
+ NEXT