4 .WARNING "uncomment LOWERCASE ADD-ON to pass coretest COMPARE ADD-ON !"
8 ;COMPARE ( c-addr1 u1 c-addr2 u2 -- n )
9 ;https://forth-standard.org/standard/string/COMPARE
10 ;Compare the string specified by c-addr1 u1 to the string specified by c-addr2 u2.
11 ;The strings are compared, beginning at the given addresses, character by character,
12 ;up to the length of the shorter string or until a difference is found.
13 ;If the two strings are identical, n is zero.
14 ;If the two strings are identical up to the length of the shorter string,
15 ; n is minus-one (-1) if u1 is less than u2 and one (1) otherwise.
16 ;If the two strings are not identical up to the length of the shorter string,
17 ; n is minus-one (-1) if the first non-matching character in the string specified by c-addr1 u1
18 ; has a lesser numeric value than the corresponding character in the string specified by c-addr2 u2 and one (1) otherwise.
22 MOV @PSP+,Y ;2 addr2 = Y
24 MOV @PSP+,X ;2 addr1 = X
27 JZ COMPEQUAL ;2 end of all successfull comparisons
31 JN COMPGREATER ;2 u2<u1
33 CMP.B @Y+,-1(X) ;4 char1-char2
34 JZ COMPAR1 ;2 char1=char2 17~ loop
35 JHS COMPGREATER ;2 char1>char2
36 COMPLESS ; char1<char2
42 MOV @IP+,PC ;4 20 words
45 ;https://forth-standard.org/standard/tools/BracketTHEN
46 FORTHWORDIMM "[THEN]" ; do nothing
55 ;Perform the execution semantics given below.
57 ;( "<spaces>name ..." -- )
58 ;Skipping leading spaces, parse and discard space-delimited words from the parse area,
59 ;including nested occurrences of [IF] ... [THEN] and [IF] ... [ELSE] ... [THEN],
60 ;until the word [THEN] has been parsed and discarded.
61 ;If the parse area becomes exhausted, it is refilled as with REFILL.
68 .word FBLANK,WORDD,COUNT ; BL WORD COUNT
69 .word DUP,QBRAN,BRACKETELSE10 ; DUP WHILE
70 .word OVER,OVER ; 2DUP
71 .word XSQUOTE ; S" [IF]"
73 .word COMPARE ; COMPARE
74 .word QZBRAN,BRACKETELSE3 ; 0= IF
75 .word TWODROP,ONEPLUS ; 2DROP 1+
76 .word BRAN,BRACKETELSE8 ; (ENDIF)
78 .word OVER,OVER ; OVER OVER
79 .word XSQUOTE ; S" [ELSE]"
81 .word COMPARE ; COMPARE
82 .word QZBRAN,BRACKETELSE5 ; 0= IF
83 .word TWODROP,ONEMIN ; 2DROP 1-
84 .word DUP,QBRAN,BRACKETELSE4 ; DUP IF
87 .word BRAN,BRACKETELSE7 ; (ENDIF)
89 .word XSQUOTE ; S" [THEN]"
91 .word COMPARE ; COMPARE
92 .word QZBRAN,BRACKETELSE6 ; 0= IF
98 .word QZBRAN,BRACKETELSE9 ; 0= IF
101 .word BRAN,BRACKETELSE2 ; REPEAT
103 .word TWODROP ; 2DROP
104 .word XSQUOTE ; CR ." ko " to show false branch of conditionnal compilation
105 .byte 4,13,107,111,32 ;
107 .word FTIB,DUP,lit,TIB_SIZE ; REFILL
108 .word ACCEPT ; -- StringOrg len' (len' <= TIB_SIZE)
110 MOV TOS,&SOURCE_LEN ; -- StringOrg len'
111 MOV @PSP+,&SOURCE_ADR ; -- len'
114 MOV #BRACKETELSE1,IP ; AGAIN
119 ;https://forth-standard.org/standard/tools/BracketIF
121 ;Perform the execution semantics given below.
122 ;Execution: ;( flag | flag "<spaces>name ..." -- )
123 ;If flag is true, do nothing. Otherwise, skipping leading spaces,
124 ; parse and discard space-delimited words from the parse area,
125 ; including nested occurrences of [IF] ... [THEN] and [IF] ... [ELSE] ... [THEN],
126 ; until either the word [ELSE] or the word [THEN] has been parsed and discarded.
127 ;If the parse area becomes exhausted, it is refilled as with REFILL. [IF] is an immediate word.
128 ;An ambiguous condition exists if [IF] is POSTPONEd,
129 ; or if the end of the input buffer is reached and cannot be refilled before the terminating [ELSE] or [THEN] is parsed.
130 FORTHWORDIMM "[IF]" ; flag --
137 ;https://forth-standard.org/standard/tools/BracketUNDEFINED
139 ;Perform the execution semantics given below.
140 ;Execution: ( "<spaces>name ..." -- flag )
141 ;Skip leading space delimiters. Parse name delimited by a space.
142 ;Return a false flag if name is the name of a word that can be found,
143 ;otherwise return a true flag.
144 FORTHWORDIMM "[UNDEFINED]"
146 .word FBLANK,WORDD,FIND,NIP,ZEROEQUAL,EXIT
149 ;https://forth-standard.org/standard/tools/BracketDEFINED
151 ;Perform the execution semantics given below.
153 ;( "<spaces>name ..." -- flag )
154 ;Skip leading space delimiters. Parse name delimited by a space.
155 ;Return a true flag if name is the name of a word that can be found,
156 ;otherwise return a false flag. [DEFINED] is an immediate word.
158 FORTHWORDIMM "[DEFINED]"
160 .word FBLANK,WORDD,FIND,NIP,EXIT
165 ;;https://forth-standard.org/standard/tools/BracketTHEN
166 ; FORTHWORDIMM ".ENDIF" ; do nothing
175 ;;Perform the execution semantics given below.
177 ;;( "<spaces>name ..." -- )
178 ;;Skipping leading spaces, parse and discard space-delimited words from the parse area,
179 ;;including nested occurrences of [IF] ... [THEN] and [IF] ... [ELSE] ... [THEN],
180 ;;until the word [THEN] has been parsed and discarded.
181 ;;If the parse area becomes exhausted, it is refilled as with REFILL.
182 ; FORTHWORDIMM ".ELSE"
187 ;BRACKETELSE1 ; BEGIN
188 ;BRACKETELSE2 ; BEGIN
189 ; .word FBLANK,WORDD,COUNT ; BL WORD COUNT
190 ; .word DUP,QBRAN,BRACKETELSE10 ; DUP WHILE
191 ; .word OVER,OVER ; 2DUP
192 ; .word XSQUOTE ; S" [IF]"
194 ; .word COMPARE ; COMPARE
195 ; .word QZBRAN,BRACKETELSE21 ; 0= IF
196 ; .word TWODROP,ONEPLUS ; 2DROP 1+
197 ; .word BRAN,BRACKETELSE8 ; (ENDIF)
199 ; .word OVER,OVER ; 2DUP
200 ; .word XSQUOTE ; S" [IF]"
201 ; .byte 7,".IFNDEF" ;
202 ; .word COMPARE ; COMPARE
203 ; .word QZBRAN,BRACKETELSE3 ; 0= IF
204 ; .word TWODROP,ONEPLUS ; 2DROP 1+
205 ; .word BRAN,BRACKETELSE8 ; (ENDIF)
207 ; .word OVER,OVER ; OVER OVER
208 ; .word XSQUOTE ; S" [ELSE]"
210 ; .word COMPARE ; COMPARE
211 ; .word QZBRAN,BRACKETELSE5 ; 0= IF
212 ; .word TWODROP,ONEMIN ; 2DROP 1-
213 ; .word DUP,QBRAN,BRACKETELSE4 ; DUP IF
216 ; .word BRAN,BRACKETELSE7 ; (ENDIF)
218 ; .word XSQUOTE ; S" [THEN]"
220 ; .word COMPARE ; COMPARE
221 ; .word QZBRAN,BRACKETELSE6 ; 0= IF
227 ; .word QZBRAN,BRACKETELSE9 ; 0= IF
230 ; .word BRAN,BRACKETELSE2 ; REPEAT
232 ; .word TWODROP ; 2DROP
233 ; .word XSQUOTE ; CR ." ko " to show false branch of conditionnal compilation
236 ; .word FTIB,DUP,lit,TIB_SIZE ; REFILL
237 ; .word ACCEPT ; -- StringOrg len' (len' <= TIB_SIZE)
239 ; MOV TOS,&SOURCE_LEN ; -- StringOrg len'
240 ; MOV @PSP+,&SOURCE_ADR ; -- len'
243 ; MOV #BRACKETELSE1,IP ; AGAIN
247 ; FORTHWORDIMM ".IFDEF"
249 ; .word FBLANK,WORDD,FIND,NIP
250 ; .WORD QBRAN,BRACKETELSE
253 ; FORTHWORDIMM ".IFNDEF"
255 ; .word FBLANK,WORDD,FIND,NIP
256 ; .WORD QZBRAN,BRACKETELSE