3 ;COMPARE ( c-addr1 u1 c-addr2 u2 -- n )
4 ;https://forth-standard.org/standard/string/COMPARE
5 ;Compare the string specified by c-addr1 u1 to the string specified by c-addr2 u2.
6 ;The strings are compared, beginning at the given addresses, character by character,
7 ;up to the length of the shorter string or until a difference is found.
8 ;If the two strings are identical, n is zero.
9 ;If the two strings are identical up to the length of the shorter string,
10 ; n is minus-one (-1) if u1 is less than u2 and one (1) otherwise.
11 ;If the two strings are not identical up to the length of the shorter string,
12 ; n is minus-one (-1) if the first non-matching character in the string specified by c-addr1 u1
13 ; has a lesser numeric value than the corresponding character in the string specified by c-addr2 u2 and one (1) otherwise.
17 MOV @PSP+,Y ;2 Y = addr2
19 MOV @PSP+,X ;2 X = addr1
21 ADD S,TOS ;1 TOS = u1+u2
22 JZ COMPEQUAL ;2 u1=u2=0: end of all successfull comparisons
24 JN COMPLESS ;2 u1<u2 if u1 < 0
26 JN COMPGREATER ;2 u1>u2 if u2 < 0
28 CMP.B @Y+,-1(X) ;4 char1-char2
29 JZ COMPAR1 ;2 char1=char2 17~ loop
30 JHS COMPGREATER ;2 char1>char2
31 COMPLESS ; char1<char2
37 MOV @IP+,PC ;4 20 words
40 ;https://forth-standard.org/standard/tools/BracketTHEN
41 FORTHWORDIMM "[THEN]" ; do nothing
45 ;;https://forth-standard.org/standard/tools/BracketELSE
47 ;;Perform the execution semantics given below.
49 ;;( "<spaces>name ..." -- )
50 ;;Skipping leading spaces, parse and discard space-delimited words from the parse area,
51 ;;including nested occurrences of [IF] ... [THEN] and [IF] ... [ELSE] ... [THEN],
52 ;;until the word [THEN] has been parsed and discarded.
53 ;;If the parse area becomes exhausted, it is refilled as with REFILL.
54 ; FORTHWORDIMM "[ELSE]"
60 ; .word FBLANK,WORDD,COUNT ; BL WORD COUNT
62 ; .word QBRAN,BRACKETELSE10 ; WHILE
63 ; .word OVER,OVER ; 2DUP
64 ; .word XSQUOTE ; S" [IF]"
66 ; .word COMPARE ; COMPARE
67 ; .word QZBRAN,BRACKETELSE3 ; 0= IF
68 ; .word TWODROP,ONEPLUS ; 2DROP 1+
69 ; .word BRAN,BRACKETELSE8 ; (ENDIF)
71 ; .word OVER,OVER ; 2DUP
72 ; .word XSQUOTE ; S" [ELSE]"
74 ; .word COMPARE ; COMPARE
75 ; .word QZBRAN,BRACKETELSE5 ; 0= IF
76 ; .word TWODROP,ONEMINUS ; 2DROP 1-
77 ; .word DUP,QBRAN,BRACKETELSE4 ; DUP IF
80 ; .word BRAN,BRACKETELSE7 ; (ENDIF)
82 ; .word XSQUOTE ; S" [THEN]"
84 ; .word COMPARE ; COMPARE
85 ; .word QZBRAN,BRACKETELSE6 ; 0= IF
91 ; .word QZBRAN,BRACKETELSE9 ; 0= IF
94 ; .word BRAN,BRACKETELSE2 ; REPEAT
96 ; .word TWODROP ; 2DROP
98 ; .byte 5,13,10,"ko " ;
99 ; .word TYPE ; CR+LF ." ko " to show false branch of conditionnal compilation
100 ; .word REFILL ; REFILL
101 ; .word SETIB ; SET Input Buffer pointers SOURCE_LEN, SOURCE_ORG and clear >IN
102 ; .word BRAN,BRACKETELSE1 ; AGAIN 65 words
105 ;[ELSE] a few (smaller and faster) definition
106 ;https://forth-standard.org/standard/tools/BracketELSE
108 ;Perform the execution semantics given below.
110 ;( "<spaces>name ..." -- )
111 ;Skipping leading spaces, parse and discard space-delimited words from the parse area,
112 ;including nested occurrences of [IF] ... [THEN] and [IF] ... [ELSE] ... [THEN],
113 ;until the word [THEN] has been parsed and discarded.
114 ;If the parse area becomes exhausted, it is refilled as with REFILL.
115 FORTHWORDIMM "[ELSE]" ; or [IF] isnogood...
122 .word FBLANK,WORDD,COUNT ;
123 .word DUP,QBRAN,BRACKETELSE5 ; if end of line refill buffer then loop back
124 .word OVER,OVER ; 2DUP
128 .word QZBRAN,BRACKETELSE2 ; if bad comparaison, jump for next comparaison
129 .word TWODROP,ONEMINUS ; 2DROP, decrement count
130 .word QDUP,QZBRAN,BRACKETELSE1; loop back if count <> 0
131 .word EXIT ; else exit
133 .word OVER,OVER ; 2DUP
137 .word QZBRAN,BRACKETELSE3 ; if bad comparaison, jump for next comparaison
138 .word TWODROP,ONEMINUS ; 2DROP, decrement count
139 .word QDUP,QZBRAN,BRACKETELSE0; if count <> 0 restore old count with loop back increment
140 .word EXIT ; else exit
145 .word QZBRAN,BRACKETELSE1 ; if bad comparaison, loop back
146 .word BRAN,BRACKETELSE0 ; else increment loop back
150 .byte 5,13,10,"ko " ;
151 .word TYPE ; CR+LF ." ko " to show false branch of conditionnal compilation
152 .word REFILL ; REFILL Input Buffer
153 .word SETIB ; SET Input Buffer pointers SOURCE_LEN, SOURCE_ORG and clear >IN
154 .word BRAN,BRACKETELSE1 ; then loop back 60 words
158 ;https://forth-standard.org/standard/tools/BracketIF
160 ;Perform the execution semantics given below.
161 ;Execution: ;( flag | flag "<spaces>name ..." -- )
162 ;If flag is true, do nothing. Otherwise, skipping leading spaces,
163 ; parse and discard space-delimited words from the parse area,
164 ; including nested occurrences of [IF] ... [THEN] and [IF] ... [ELSE] ... [THEN],
165 ; until either the word [ELSE] or the word [THEN] has been parsed and discarded.
166 ;If the parse area becomes exhausted, it is refilled as with REFILL. [IF] is an immediate word.
167 ;An ambiguous condition exists if [IF] is POSTPONEd,
168 ; or if the end of the input buffer is reached and cannot be refilled before the terminating [ELSE] or [THEN] is parsed.
169 FORTHWORDIMM "[IF]" ; flag --
177 ;https://forth-standard.org/standard/tools/BracketDEFINED
179 ;Perform the execution semantics given below.
181 ;( "<spaces>name ..." -- flag )
182 ;Skip leading space delimiters. Parse name delimited by a space.
183 ;Return a true flag if name is the name of a word that can be found,
184 ;otherwise return a false flag. [DEFINED] is an immediate word.
186 FORTHWORDIMM "[DEFINED]"
188 .word FBLANK,WORDD,FIND,NIP,EXIT
191 ;https://forth-standard.org/standard/tools/BracketUNDEFINED
193 ;Perform the execution semantics given below.
194 ;Execution: ( "<spaces>name ..." -- flag )
195 ;Skip leading space delimiters. Parse name delimited by a space.
196 ;Return a false flag if name is the name of a word that can be found,
197 ;otherwise return a true flag.
198 FORTHWORDIMM "[UNDEFINED]"
200 .word FBLANK,WORDD,FIND,NIP,ZEROEQUAL,EXIT
203 ;;https://forth-standard.org/standard/core/MARKER
204 ;;( "<spaces>name" -- )
205 ;;Skip leading space delimiters. Parse name delimited by a space. Create a definition for name
206 ;;with the execution semantics defined below.
208 ;;name Execution: ( -- )
209 ;;Restore all dictionary allocation and search order pointers to the state they had just prior to the
210 ;;definition of name. Remove the definition of name and all subsequent definitions. Restoration
211 ;;of any structures still existing that could refer to deleted definitions or deallocated data space is
212 ;;not necessarily provided. No other contextual information such as numeric base is affected
214 MARKER_DOES FORTHtoASM ; execution part
215 MOV @RSP+,IP ; -- PFA
216 MOV @TOS+,&INIVOC ; set VOC_LINK value for RST_STATE
217 MOV @TOS,&INIDP ; set DP value for RST_STATE
219 JMP RST_STATE ; execute RST_STATE, PWR_STATE then STATE_DOES
221 FORTHWORD "MARKER" ; definition part
222 CALL #HEADER ;4 W = DP+4
223 MOV #DODOES,-4(W) ;4 CFA = DODOES
224 MOV #MARKER_DOES,-2(W) ;4 PFA = MARKER_DOES
225 MOV &LASTVOC,0(W) ;5 [BODY] = VOCLINK to be restored
227 MOV Y,2(W) ;3 [BODY+2] = LFA = DP to be restored
231 ; the next in forthMSP430FR.asm is GOOD_CSP