aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/msp430/words/s-equal.asm
diff options
context:
space:
mode:
Diffstat (limited to 'amforth-6.5/msp430/words/s-equal.asm')
-rw-r--r--amforth-6.5/msp430/words/s-equal.asm19
1 files changed, 19 insertions, 0 deletions
diff --git a/amforth-6.5/msp430/words/s-equal.asm b/amforth-6.5/msp430/words/s-equal.asm
new file mode 100644
index 0000000..28e6758
--- /dev/null
+++ b/amforth-6.5/msp430/words/s-equal.asm
@@ -0,0 +1,19 @@
+;Z S= c-addr1 c-addr2 u -- n string compare
+;Z n<0: s1<s2, n=0: s1=s2, n>0: s1>s2
+ CODEHEADER(XT_SEQUAL,2,"s=")
+ MOV @PSP+,W ; adrs2
+ MOV @PSP+,X ; adrs1
+ CMP #0,TOS
+ JZ SEQU_X
+SEQU_1: CMP.B @W+,0(X) ; compare char1-char2
+ JNZ SMISMATCH
+ ADD #1,X
+ SUB #1,TOS
+ JNZ SEQU_1
+ ; no mismatch found, strings are equal, TOS=0
+ JMP SEQU_X
+ ; mismatch found, CY clear if borrow set (s1<s2)
+SMISMATCH: SUBC TOS,TOS ; TOS=-1 if borrow was set
+ ADD TOS,TOS ; TOS=-2 or 0
+ ADD #1,TOS ; TOS=-1 or +1
+SEQU_X: NEXT ; return result in TOS