4 .WARNING "uncomment LOWERCASE ADD-ON to pass coretest COMPARE !"
7 ;COMPARE ( c-addr1 u1 c-addr2 u2 -- n )
8 ;https://forth-standard.org/standard/string/COMPARE
9 ;Compare the string specified by c-addr1 u1 to the string specified by c-addr2 u2.
10 ;The strings are compared, beginning at the given addresses, character by character,
11 ;up to the length of the shorter string or until a difference is found.
12 ;If the two strings are identical, n is zero.
13 ;If the two strings are identical up to the length of the shorter string,
14 ; n is minus-one (-1) if u1 is less than u2 and one (1) otherwise.
15 ;If the two strings are not identical up to the length of the shorter string,
16 ; n is minus-one (-1) if the first non-matching character in the string specified by c-addr1 u1
17 ; has a lesser numeric value than the corresponding character in the string specified by c-addr2 u2 and one (1) otherwise.
21 MOV @PSP+,Y ;2 addr2 = Y
23 MOV @PSP+,X ;2 addr1 = X
26 JZ COMPEQUAL ;2 end of all successfull comparisons
30 JN COMPGREATER ;2 u2<u1
32 CMP.B @Y+,-1(X) ;4 char1-char2
33 JZ COMPAR1 ;2 char1=char2 17~ loop
34 JHS COMPGREATER ;2 char1>char2
35 COMPLESS ; char1<char2
41 MOV @IP+,PC ;4 20 words
44 ;https://forth-standard.org/standard/tools/BracketTHEN
45 FORTHWORDIMM "[THEN]" ; do nothing
54 ;Perform the execution semantics given below.
56 ;( "<spaces>name ..." -- )
57 ;Skipping leading spaces, parse and discard space-delimited words from the parse area,
58 ;including nested occurrences of [IF] ... [THEN] and [IF] ... [ELSE] ... [THEN],
59 ;until the word [THEN] has been parsed and discarded.
60 ;If the parse area becomes exhausted, it is refilled as with REFILL.
67 .word FBLANK,WORDD,COUNT ; BL WORD COUNT
68 .word DUP,QBRAN,BRACKETELSE10 ; DUP WHILE
69 .word OVER,OVER ; 2DUP
70 .word XSQUOTE ; S" [IF]"
72 .word COMPARE ; COMPARE
73 .word QZBRAN,BRACKETELSE3 ; 0= IF
74 .word TWODROP,ONEPLUS ; 2DROP 1+
75 .word BRAN,BRACKETELSE8 ; (ENDIF)
77 .word OVER,OVER ; OVER OVER
78 .word XSQUOTE ; S" [ELSE]"
80 .word COMPARE ; COMPARE
81 .word QZBRAN,BRACKETELSE5 ; 0= IF
82 .word TWODROP,ONEMIN ; 2DROP 1-
83 .word DUP,QBRAN,BRACKETELSE4 ; DUP IF
86 .word BRAN,BRACKETELSE7 ; (ENDIF)
88 .word XSQUOTE ; S" [THEN]"
90 .word COMPARE ; COMPARE
91 .word QZBRAN,BRACKETELSE6 ; 0= IF
97 .word QZBRAN,BRACKETELSE9 ; 0= IF
100 .word BRAN,BRACKETELSE2 ; REPEAT
102 .word TWODROP ; 2DROP
104 ; .byte 3,13,107,111 ;
105 ; .word TYPE,SPACE ; CR ." ko " to show false branch of conditionnal compilation
106 .byte 5,13,10,"ko " ;
107 .word TYPE ; CR+LF ." ko " to show false branch of conditionnal compilation
108 .word FCIB,DUP,CPL ; )
110 .word ACCEPT ; -- CIB len )
113 MOV TOS,&SOURCE_LEN ; -- CIB len
114 MOV @PSP+,&SOURCE_ADR ; -- len'
116 MOV #BRACKETELSE1,IP ; AGAIN
121 ;https://forth-standard.org/standard/tools/BracketIF
123 ;Perform the execution semantics given below.
124 ;Execution: ;( flag | flag "<spaces>name ..." -- )
125 ;If flag is true, do nothing. Otherwise, skipping leading spaces,
126 ; parse and discard space-delimited words from the parse area,
127 ; including nested occurrences of [IF] ... [THEN] and [IF] ... [ELSE] ... [THEN],
128 ; until either the word [ELSE] or the word [THEN] has been parsed and discarded.
129 ;If the parse area becomes exhausted, it is refilled as with REFILL. [IF] is an immediate word.
130 ;An ambiguous condition exists if [IF] is POSTPONEd,
131 ; or if the end of the input buffer is reached and cannot be refilled before the terminating [ELSE] or [THEN] is parsed.
132 FORTHWORDIMM "[IF]" ; flag --
139 ;https://forth-standard.org/standard/tools/BracketUNDEFINED
141 ;Perform the execution semantics given below.
142 ;Execution: ( "<spaces>name ..." -- flag )
143 ;Skip leading space delimiters. Parse name delimited by a space.
144 ;Return a false flag if name is the name of a word that can be found,
145 ;otherwise return a true flag.
146 FORTHWORDIMM "[UNDEFINED]"
148 .word FBLANK,WORDD,FIND,NIP,ZEROEQUAL,EXIT
151 ;https://forth-standard.org/standard/tools/BracketDEFINED
153 ;Perform the execution semantics given below.
155 ;( "<spaces>name ..." -- flag )
156 ;Skip leading space delimiters. Parse name delimited by a space.
157 ;Return a true flag if name is the name of a word that can be found,
158 ;otherwise return a false flag. [DEFINED] is an immediate word.
160 FORTHWORDIMM "[DEFINED]"
162 .word FBLANK,WORDD,FIND,NIP,EXIT
165 ;;https://forth-standard.org/standard/core/MARKER
166 ;;( "<spaces>name" -- )
167 ;;Skip leading space delimiters. Parse name delimited by a space. Create a definition for name
168 ;;with the execution semantics defined below.
170 ;;name Execution: ( -- )
171 ;;Restore all dictionary allocation and search order pointers to the state they had just prior to the
172 ;;definition of name. Remove the definition of name and all subsequent definitions. Restoration
173 ;;of any structures still existing that could refer to deleted definitions or deallocated data space is
174 ;;not necessarily provided. No other contextual information such as numeric base is affected
176 MARKER_DOES FORTHtoASM ; execution part
177 MOV @RSP+,IP ; -- PFA
178 MOV @TOS+,&INIVOC ; set VOC_LINK value for RST_STATE
179 MOV @TOS,&INIDP ; set DP value for RST_STATE
181 JMP RST_STATE ; execute RST_STATE, PWR_STATE then STATE_DOES
183 FORTHWORD "MARKER" ; definition part
184 CALL #HEADER ;4 W = DP+4
185 MOV #DODOES,-4(W) ;4 CFA = DODOES
186 MOV #MARKER_DOES,-2(W) ;4 PFA = MARKER_DOES
187 MOV &LASTVOC,0(W) ;5 [BODY] = VOCLINK to be restored
189 MOV Y,2(W) ;3 [BODY+2] = LFA = DP to be restored
191 ; the next is GOOD_CSP in forthMSP430FR.asm