2 ; -----------------------------------------------------
3 ; ANS_COMP.f words complement to pass CORETEST.4th
4 ; -----------------------------------------------------
6 \ to see kernel options, download FastForthSpecs.f
7 \ FastForth kernel options: MSP430ASSEMBLER, CONDCOMP
9 \ TARGET Current Selection
10 \ (used by preprocessor GEMA to load the pattern: \config\gema\TARGET.pat)
11 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
12 \ MSP_EXP430FR2433 MSP_EXP430FR4133 MSP_EXP430FR2355 CHIPSTICK_FR2433
15 \ rDODOES to rEXIT must be saved before use and restored after
16 \ scratch registers Y to S are free for use
17 \ under interrupt, IP is free for use
19 \ PUSHM order : PSP,TOS, IP, S, T, W, X, Y, rEXIT, rDOVAR, rDOCON, rDODOES
20 \ example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
22 \ POPM order : rDODOES, rDOCON, rDOVAR, rEXIT, Y, X, W, T, S, IP,TOS,PSP
23 \ example : POPM #6,IP pulls Y,X,W,T,S,IP registers from return stack
25 \ FORTH conditionnals: unary{ 0= 0< 0> }, binary{ = < > U< }
27 \ ASSEMBLER conditionnal usage with IF UNTIL WHILE S< S>= U< U>= 0= 0<> 0>=
28 \ ASSEMBLER conditionnal usage with ?JMP ?GOTO S< S>= U< U>= 0= 0<> 0<
32 [DEFINED] {ANS_COMP} [IF] {ANS_COMP} [THEN] \ remove {ANS_COMP} if outside protected core
35 ECHO ASM ; assembler is required! <--
38 [UNDEFINED] {ANS_COMP} [IF]
43 \ https://forth-standard.org/standard/core/AND
44 \ C AND x1 x2 -- x3 logical AND
52 \ https://forth-standard.org/standard/core/OR
53 \ C OR x1 x2 -- x3 logical OR
61 \ https://forth-standard.org/standard/core/XOR
62 \ C XOR x1 x2 -- x3 logical XOR
69 \ https://forth-standard.org/standard/core/INVERT
70 \ INVERT x1 -- x2 bitwise inversion
76 \ https://forth-standard.org/standard/core/LSHIFT
77 \ LSHIFT x1 u -- x2 logical L shift u places
80 AND #$1F,TOS \ no need to shift more than 16
89 \ https://forth-standard.org/standard/core/RSHIFT
90 \ RSHIFT x1 u -- x2 logical R7 shift u places
93 AND #$1F,TOS \ no need to shift more than 16
95 BEGIN BIC #C,SR \ Clr Carry
104 \ https://forth-standard.org/standard/core/MAX
105 \ MAX n1 n2 -- n3 signed maximum
113 \ https://forth-standard.org/standard/core/MIN
114 \ MIN n1 n2 -- n3 signed minimum
123 \ https://forth-standard.org/standard/core/TwoTimes
124 \ 2* x1 -- x2 arithmetic left shift
130 \ https://forth-standard.org/standard/core/TwoDiv
131 \ 2/ x1 -- x2 arithmetic right shift
137 \ --------------------
138 \ ARITHMETIC OPERATORS
139 \ --------------------
140 $1A04 C@ $EF > [IF] ; test tag value MSP430FR413x subfamily without hardware_MPY
142 \ https://forth-standard.org/standard/core/MTimes
143 \ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
148 XOR #-1,0(PSP) \ n1 --> u1
151 XOR TOS,S \ S contains sign of result
152 CMP #0,TOS \ n2 > -1 ?
154 XOR #-1,TOS \ n2 --> u2
157 PUSHM #2,IP \ UMSTAR use S,T,W,X,Y
161 POPM #2,IP \ pop S,IP
162 CMP #0,S \ sign of result > -1 ?
164 XOR #-1,0(PSP) \ ud --> d
172 [ELSE] ; MSP430FRxxxx with hardware_MPY
174 \ https://forth-standard.org/standard/core/UMTimes
175 \ UM* u1 u2 -- udlo udhi unsigned 16x16->32 mult.
177 MOV @PSP,&MPY \ Load 1st operand for unsigned multiplication
178 BW1 MOV TOS,&OP2 \ Load 2nd operand
179 MOV &RES0,0(PSP) \ low result on stack
180 MOV &RES1,TOS \ high result in TOS
184 \ https://forth-standard.org/standard/core/MTimes
185 \ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
187 MOV @PSP,&MPYS \ Load 1st operand for signed multiplication
193 \ https://forth-standard.org/standard/core/SMDivREM
194 \ SM/REM d1lo d1hi n2 -- r3 q4 symmetric signed div
196 MOV TOS,S \ S=divisor
197 MOV @PSP,T \ T=dividend_sign==>rem_sign
198 CMP #0,TOS \ n2 >= 0 ?
201 ADD #1,TOS \ -- d1 u2
203 CMP #0,0(PSP) \ d1hi >= 0 ?
205 XOR #-1,2(PSP) \ d1lo
206 XOR #-1,0(PSP) \ d1hi
207 ADD #1,2(PSP) \ d1lo+1
208 ADDC #0,0(PSP) \ d1hi+C
209 THEN \ -- uDVDlo uDVDhi uDIVlo
210 PUSHM #3,IP \ save IP,S,T
212 UM/MOD \ -- uREMlo uQUOTlo
214 POPM #3,IP \ restore T,S,IP
215 CMP #0,T \ T=rem_sign
220 XOR S,T \ S=divisor T=quot_sign
221 CMP #0,T \ -- n3 u4 T=quot_sign
227 THEN \ -- n3 n4 S=divisor
231 \ https://forth-standard.org/standard/core/NEGATE
232 \ C NEGATE x1 -- x2 two's complement
237 \ https://forth-standard.org/standard/core/ABS
238 \ C ABS n1 -- +n2 absolute value
245 \ https://forth-standard.org/standard/core/FMDivMOD
246 \ FM/MOD d1 n1 -- r q floored signed div'n
249 HI2LO \ -- remainder quotient S=divisor
250 CMP #0,0(PSP) \ remainder <> 0 ?
252 CMP #1,TOS \ quotient < 1 ?
254 ADD S,0(PSP) \ add divisor to remainder
255 SUB #1,TOS \ decrement quotient
262 \ https://forth-standard.org/standard/core/Times
263 \ * n1 n2 -- n3 signed multiply
268 \ https://forth-standard.org/standard/core/DivMOD
269 \ /MOD n1 n2 -- r3 q4 signed division
274 \ https://forth-standard.org/standard/core/Div
275 \ / n1 n2 -- n3 signed quotient
277 >R DUP 0< R> FM/MOD NIP
280 \ https://forth-standard.org/standard/core/MOD
281 \ MOD n1 n2 -- n3 signed remainder
283 >R DUP 0< R> FM/MOD DROP
286 \ https://forth-standard.org/standard/core/TimesDivMOD
287 \ */MOD n1 n2 n3 -- r4 q5 signed mult/div
292 \ https://forth-standard.org/standard/core/TimesDiv
293 \ */ n1 n2 n3 -- n4 n1*n2/q3
298 \ ----------------------------------------------------------------------
300 \ ----------------------------------------------------------------------
302 \ https://forth-standard.org/standard/core/StoD
303 \ S>D n -- d single -> double prec.
308 \ https://forth-standard.org/standard/core/TwoFetch
309 \ 2@ a-addr -- x1 x2 fetch 2 cells ; the lower address will appear on top of stack
317 \ https://forth-standard.org/standard/core/TwoStore
318 \ 2! x1 x2 a-addr -- store 2 cells ; the top of stack is stored at the lower adr
326 \ https://forth-standard.org/standard/core/TwoDUP
327 \ 2DUP x1 x2 -- x1 x2 x1 x2 dup top 2 cells
329 SUB #4,PSP \ -- x1 x x x2
330 MOV TOS,2(PSP) \ -- x1 x2 x x2
331 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x2
335 \ https://forth-standard.org/standard/core/TwoDROP
336 \ 2DROP x1 x2 -- drop 2 cells
343 \ https://forth-standard.org/standard/core/TwoSWAP
344 \ 2SWAP x1 x2 x3 x4 -- x3 x4 x1 x2
346 MOV @PSP,W \ -- x1 x2 x3 x4 W=x3
347 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x4
348 MOV W,4(PSP) \ -- x3 x2 x1 x4
349 MOV TOS,W \ -- x3 x2 x1 x4 W=x4
350 MOV 2(PSP),TOS \ -- x3 x2 x1 x2 W=x4
351 MOV W,2(PSP) \ -- x3 x4 x1 x2
355 \ https://forth-standard.org/standard/core/TwoOVER
356 \ 2OVER x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2
358 SUB #4,PSP \ -- x1 x2 x3 x x x4
359 MOV TOS,2(PSP) \ -- x1 x2 x3 x4 x x4
360 MOV 8(PSP),0(PSP) \ -- x1 x2 x3 x4 x1 x4
361 MOV 6(PSP),TOS \ -- x1 x2 x3 x4 x1 x2
365 \ ----------------------------------------------------------------------
366 \ ALIGNMENT OPERATORS
367 \ ----------------------------------------------------------------------
368 \ https://forth-standard.org/standard/core/ALIGNED
369 \ ALIGNED addr -- a-addr align given addr
376 \ https://forth-standard.org/standard/core/ALIGN
377 \ ALIGN -- align HERE
384 \ ---------------------
385 \ PORTABILITY OPERATORS
386 \ ---------------------
387 \ https://forth-standard.org/standard/core/CHARS
388 \ CHARS n1 -- n2 chars->adrs units
393 \ https://forth-standard.org/standard/core/CHARPlus
394 \ CHAR+ c-addr1 -- c-addr2 add char size
400 \ https://forth-standard.org/standard/core/CELLS
401 \ CELLS n1 -- n2 cells->adrs units
407 \ https://forth-standard.org/standard/core/CELLPlus
408 \ CELL+ a-addr1 -- a-addr2 add cell size
414 \ ---------------------------
415 \ BLOCK AND STRING COMPLEMENT
416 \ ---------------------------
417 \ https://forth-standard.org/standard/core/CHAR
418 \ CHAR -- char parse ASCII character
423 \ https://forth-standard.org/standard/core/BracketCHAR
424 \ [CHAR] -- compile character literal
429 \ https://forth-standard.org/standard/core/PlusStore
430 \ +! n/u a-addr -- add n/u to memory
437 \ https://forth-standard.org/standard/core/FILL
438 \ FILL c-addr u char -- fill memory with char
441 MOV @PSP+,W \ address
445 MOV.B TOS,0(W) \ store char in memory
450 MOV @PSP+,TOS \ empties stack
454 \ --------------------
455 \ INTERPRET COMPLEMENT
456 \ --------------------
457 \ https://forth-standard.org/standard/core/HEX
463 \ https://forth-standard.org/standard/core/DECIMAL
469 \ https://forth-standard.org/standard/core/p
470 \ ( -- skip input until char ) or EOL
475 \ https://forth-standard.org/standard/core/Dotp
476 \ .( -- type comment immediatly.
478 MOV #0,&CAPS \ CAPS OFF
485 \ https://forth-standard.org/standard/core/SOURCE
486 \ SOURCE -- adr u of current input buffer
491 MOV &SOURCE_ADR,0(PSP)
495 \ https://forth-standard.org/standard/core/toIN
496 \ C >IN -- a-addr holds offset in input stream
501 \ https://forth-standard.org/standard/core/PAD