1 ; ------------------------------------------------------------------------------
2 ; ANS_COMP.f words complement to pass CORETEST.4th
3 ; ------------------------------------------------------------------------------
5 \ TARGET SELECTION (used by preprocessor GEMA to load \config\gema\TARGET.pat)
6 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
7 \ MSP_EXP430FR2433 MSP_EXP430FR4133 MSP_EXP430FR2355 CHIPSTICK_FR2433
8 \ MY_MSP430FR5738_1 MY_MSP430FR5738 MY_MSP430FR5948 MY_MSP430FR5948_1
12 \ rDODOES to rEXIT must be saved before use and restored after
13 \ scratch registers Y to S are free for use
14 \ under interrupt, IP is free for use
16 \ PUSHM order : PSP,TOS, IP, S, T, W, X, Y, rEXIT, rDOVAR, rDOCON, rDODOES
17 \ example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
19 \ POPM order : rDODOES, rDOCON, rDOVAR, rEXIT, Y, X, W, T, S, IP,TOS,PSP
20 \ example : POPM #6,IP pulls Y,X,W,T,S,IP registers from return stack
22 \ FORTH conditionnals: unary{ 0= 0< 0> }, binary{ = < > U< }
24 \ ASSEMBLER conditionnal usage with IF UNTIL WHILE S< S>= U< U>= 0= 0<> 0>=
26 \ ASSEMBLER conditionnal usage with ?JMP ?GOTO S< S>= U< U>= 0= 0<> <0
31 [DEFINED] {ANS_COMP} [IF] {ANS_COMP} [THEN] \ remove {ANS_COMP} if outside core
35 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
51 \ https://forth-standard.org/standard/core/OR
52 \ C OR x1 x2 -- x3 logical OR
59 \ https://forth-standard.org/standard/core/XOR
60 \ C XOR x1 x2 -- x3 logical XOR
67 \ https://forth-standard.org/standard/core/INVERT
68 \ INVERT x1 -- x2 bitwise inversion
75 \ https://forth-standard.org/standard/core/LSHIFT
76 \ LSHIFT x1 u -- x2 logical L shift u places
79 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
105 \ https://forth-standard.org/standard/core/MAX
106 \ MAX n1 n2 -- n3 signed maximum
115 \ https://forth-standard.org/standard/core/MIN
116 \ MIN n1 n2 -- n3 signed minimum
126 \ https://forth-standard.org/standard/core/TwoTimes
127 \ 2* x1 -- x2 arithmetic left shift
134 \ https://forth-standard.org/standard/core/TwoDiv
135 \ 2/ x1 -- x2 arithmetic right shift
142 \ --------------------
143 \ ARITHMETIC OPERATORS
144 \ --------------------
146 $1A04 C@ $EF > [IF] ; test tag value MSP430FR413x subfamily without hardware_MPY
148 \ https://forth-standard.org/standard/core/MTimes
149 \ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
154 XOR #-1,0(PSP) \ n1 --> u1
157 XOR TOS,S \ S contains sign of result
158 CMP #0,TOS \ n2 > -1 ?
160 XOR #-1,TOS \ n2 --> u2
163 \ PUSHM IP,S \ UMSTAR use S,T,W,X,Y
164 PUSHM #2,IP \ UMSTAR use S,T,W,X,Y
168 POPM #2,IP \ pop S,IP
169 CMP #0,S \ sign of result > -1 ?
171 XOR #-1,0(PSP) \ ud --> d
179 [ELSE] ; MSP430FRxxxx with hardware_MPY
181 \ https://forth-standard.org/standard/core/UMTimes
182 \ UM* u1 u2 -- udlo udhi unsigned 16x16->32 mult.
184 MOV @PSP,&MPY \ Load 1st operand for unsigned multiplication
185 BW1 MOV TOS,&OP2 \ Load 2nd operand
186 MOV &RES0,0(PSP) \ low result on stack
187 MOV &RES1,TOS \ high result in TOS
192 \ https://forth-standard.org/standard/core/MTimes
193 \ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
195 MOV @PSP,&MPYS \ Load 1st operand for signed multiplication
204 \ https://forth-standard.org/standard/core/SMDivREM
205 \ SM/REM d1lo d1hi n2 -- r3 q4 symmetric signed div
207 MOV TOS,S \ S=divisor
208 MOV @PSP,T \ T=dividend_sign==>rem_sign
209 CMP #0,TOS \ n2 >= 0 ?
212 ADD #1,TOS \ -- d1 u2
214 CMP #0,0(PSP) \ d1hi >= 0 ?
216 XOR #-1,2(PSP) \ d1lo
217 XOR #-1,0(PSP) \ d1hi
218 ADD #1,2(PSP) \ d1lo+1
219 ADDC #0,0(PSP) \ d1hi+C
220 THEN \ -- uDVDlo uDVDhi uDIVlo
221 \ PUSHM IP,T \ save IP,S,T
222 PUSHM #3,IP \ save IP,S,T
224 UM/MOD \ -- uREMlo uQUOTlo
226 \ POPM T,IP \ restore T,S,IP
227 POPM #3,IP \ restore T,S,IP
228 CMP #0,T \ T=rem_sign
233 XOR S,T \ S=divisor T=quot_sign
234 CMP #0,T \ -- n3 u4 T=quot_sign
240 THEN \ -- n3 n4 S=divisor
247 \ https://forth-standard.org/standard/core/NEGATE
248 \ C NEGATE x1 -- x2 two's complement
254 \ https://forth-standard.org/standard/core/ABS
255 \ C ABS n1 -- +n2 absolute value
263 \ https://forth-standard.org/standard/core/FMDivMOD
264 \ FM/MOD d1 n1 -- r q floored signed div'n
267 HI2LO \ -- remainder quotient S=divisor
268 CMP #0,0(PSP) \ remainder <> 0 ?
270 CMP #1,TOS \ quotient < 1 ?
272 ADD S,0(PSP) \ add divisor to remainder
273 SUB #1,TOS \ decrement quotient
281 \ https://forth-standard.org/standard/core/Times
282 \ * n1 n2 -- n3 signed multiply
288 \ https://forth-standard.org/standard/core/DivMOD
289 \ /MOD n1 n2 -- r3 q4 signed division
295 \ https://forth-standard.org/standard/core/Div
296 \ / n1 n2 -- n3 signed quotient
298 >R DUP 0< R> FM/MOD NIP
302 \ https://forth-standard.org/standard/core/MOD
303 \ MOD n1 n2 -- n3 signed remainder
305 >R DUP 0< R> FM/MOD DROP
309 \ https://forth-standard.org/standard/core/TimesDivMOD
310 \ */MOD n1 n2 n3 -- r4 q5 signed mult/div
316 \ https://forth-standard.org/standard/core/TimesDiv
317 \ */ n1 n2 n3 -- n4 n1*n2/q3
323 \ ----------------------------------------------------------------------
325 \ ----------------------------------------------------------------------
327 \ https://forth-standard.org/standard/core/StoD
328 \ S>D n -- d single -> double prec.
334 \ https://forth-standard.org/standard/core/TwoFetch
335 \ 2@ a-addr -- x1 x2 fetch 2 cells ; the lower address will appear on top of stack
344 \ https://forth-standard.org/standard/core/TwoStore
345 \ 2! x1 x2 a-addr -- store 2 cells ; the top of stack is stored at the lower adr
354 \ https://forth-standard.org/standard/core/TwoDUP
355 \ 2DUP x1 x2 -- x1 x2 x1 x2 dup top 2 cells
357 SUB #4,PSP \ -- x1 x x x2
358 MOV TOS,2(PSP) \ -- x1 x2 x x2
359 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x2
364 \ https://forth-standard.org/standard/core/TwoDROP
365 \ 2DROP x1 x2 -- drop 2 cells
373 \ https://forth-standard.org/standard/core/TwoSWAP
374 \ 2SWAP x1 x2 x3 x4 -- x3 x4 x1 x2
376 MOV @PSP,W \ -- x1 x2 x3 x4 W=x3
377 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x4
378 MOV W,4(PSP) \ -- x3 x2 x1 x4
379 MOV TOS,W \ -- x3 x2 x1 x4 W=x4
380 MOV 2(PSP),TOS \ -- x3 x2 x1 x2 W=x4
381 MOV W,2(PSP) \ -- x3 x4 x1 x2
386 \ https://forth-standard.org/standard/core/TwoOVER
387 \ 2OVER x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2
389 SUB #4,PSP \ -- x1 x2 x3 x x x4
390 MOV TOS,2(PSP) \ -- x1 x2 x3 x4 x x4
391 MOV 8(PSP),0(PSP) \ -- x1 x2 x3 x4 x1 x4
392 MOV 6(PSP),TOS \ -- x1 x2 x3 x4 x1 x2
397 \ ----------------------------------------------------------------------
398 \ ALIGNMENT OPERATORS
399 \ ----------------------------------------------------------------------
401 \ https://forth-standard.org/standard/core/ALIGNED
402 \ ALIGNED addr -- a-addr align given addr
410 \ https://forth-standard.org/standard/core/ALIGN
411 \ ALIGN -- align HERE
419 \ ---------------------
420 \ PORTABILITY OPERATORS
421 \ ---------------------
423 \ https://forth-standard.org/standard/core/CHARS
424 \ CHARS n1 -- n2 chars->adrs units
430 \ https://forth-standard.org/standard/core/CHARPlus
431 \ CHAR+ c-addr1 -- c-addr2 add char size
438 \ https://forth-standard.org/standard/core/CELLS
439 \ CELLS n1 -- n2 cells->adrs units
446 \ https://forth-standard.org/standard/core/CELLPlus
447 \ CELL+ a-addr1 -- a-addr2 add cell size
453 \ ---------------------------
454 \ BLOCK AND STRING COMPLEMENT
455 \ ---------------------------
457 \ https://forth-standard.org/standard/core/CHAR
458 \ CHAR -- char parse ASCII character
463 \ https://forth-standard.org/standard/core/BracketCHAR
464 \ [CHAR] -- compile character literal
471 \ https://forth-standard.org/standard/core/PlusStore
472 \ +! n/u a-addr -- add n/u to memory
480 \ https://forth-standard.org/standard/core/FILL
481 \ FILL c-addr u char -- fill memory with char
484 MOV @PSP+,W \ address
488 MOV.B TOS,0(W) \ store char in memory
493 MOV @PSP+,TOS \ empties stack
498 \ --------------------
499 \ INTERPRET COMPLEMENT
500 \ --------------------
502 \ https://forth-standard.org/standard/core/HEX
509 \ https://forth-standard.org/standard/core/DECIMAL
516 \ https://forth-standard.org/standard/core/p
517 \ ( -- skip input until char ) or EOL
523 [DEFINED] CAPS_ON [IF]
525 \ https://forth-standard.org/standard/core/Dotp
526 \ .( -- type comment immediatly.
535 \ https://forth-standard.org/standard/core/Dotp
536 \ .( -- type comment immediatly.
545 \ https://forth-standard.org/standard/core/SOURCE
546 \ SOURCE -- adr u of current input buffer
551 MOV &SOURCE_ADR,0(PSP)
556 \ https://forth-standard.org/standard/core/toIN
557 \ C >IN -- a-addr holds offset in input stream
563 \ https://forth-standard.org/standard/core/PAD