1 ; ------------------------------------------------------------------------------
2 ; ANS_COMP.f words complement to pass CORETEST.4th
3 ; ------------------------------------------------------------------------------
6 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
7 \ MSP_EXP430FR2433 MSP_EXP430FR4133 CHIPSTICK_FR2433
8 \ MY_MSP430FR5738_1 MY_MSP430FR5738 MY_MSP430FR5948 MY_MSP430FR5948_1
13 [DEFINED] {ANS_COMP} [IF] {ANS_COMP} [THEN] \ remove {ANS_COMP} if outside core
17 ASM ; assembler is required!
20 [UNDEFINED] {ANS_COMP} [IF]
25 \ https://forth-standard.org/standard/core/AND
26 \ C AND x1 x2 -- x3 logical AND
33 \ https://forth-standard.org/standard/core/OR
34 \ C OR x1 x2 -- x3 logical OR
41 \ https://forth-standard.org/standard/core/XOR
42 \ C XOR x1 x2 -- x3 logical XOR
49 \ https://forth-standard.org/standard/core/INVERT
50 \ INVERT x1 -- x2 bitwise inversion
57 \ https://forth-standard.org/standard/core/LSHIFT
58 \ LSHIFT x1 u -- x2 logical L shift u places
61 AND #$1F,TOS \ no need to shift more than 16
71 \ https://forth-standard.org/standard/core/RSHIFT
72 \ RSHIFT x1 u -- x2 logical R7 shift u places
75 AND #$1F,TOS \ no need to shift more than 16
77 BEGIN BIC #C,SR \ Clr Carry
87 \ https://forth-standard.org/standard/core/MAX
88 \ MAX n1 n2 -- n3 signed maximum
97 \ https://forth-standard.org/standard/core/MIN
98 \ MIN n1 n2 -- n3 signed minimum
108 \ https://forth-standard.org/standard/core/TwoTimes
109 \ 2* x1 -- x2 arithmetic left shift
116 \ https://forth-standard.org/standard/core/TwoDiv
117 \ 2/ x1 -- x2 arithmetic right shift
124 \ --------------------
125 \ ARITHMETIC OPERATORS
126 \ --------------------
128 $1A04 C@ $EF > [IF] ; test tag value MSP430FR413x subfamily without hardware_MPY
130 \ https://forth-standard.org/standard/core/MTimes
131 \ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
136 XOR #-1,0(PSP) \ n1 --> u1
139 XOR TOS,S \ S contains sign of result
140 CMP #0,TOS \ n2 > -1 ?
142 XOR #-1,TOS \ n2 --> u2
145 PUSHM IP,S \ UMSTAR use S,T,W,X,Y
150 CMP #0,S \ sign of result > -1 ?
152 XOR #-1,0(PSP) \ ud --> d
160 [ELSE] ; MSP430FRxxxx with hardware_MPY
162 \ https://forth-standard.org/standard/core/UMTimes
163 \ UM* u1 u2 -- udlo udhi unsigned 16x16->32 mult.
165 MOV @PSP,&MPY \ Load 1st operand for unsigned multiplication
166 BW1 MOV TOS,&OP2 \ Load 2nd operand
167 MOV &RES0,0(PSP) \ low result on stack
168 MOV &RES1,TOS \ high result in TOS
173 \ https://forth-standard.org/standard/core/MTimes
174 \ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
176 MOV @PSP,&MPYS \ Load 1st operand for signed multiplication
183 \ https://forth-standard.org/standard/core/SMDivREM
184 \ SM/REM d1lo d1hi n2 -- r3 q4 symmetric signed div
186 MOV TOS,S \ S=divisor
187 MOV @PSP,T \ T=dividend_sign==>rem_sign
188 CMP #0,TOS \ n2 >= 0 ?
191 ADD #1,TOS \ -- d1 u2
193 CMP #0,0(PSP) \ d1hi >= 0 ?
195 XOR #-1,2(PSP) \ d1lo
196 XOR #-1,0(PSP) \ d1hi
197 ADD #1,2(PSP) \ d1lo+1
198 ADDC #0,0(PSP) \ d1hi+C
199 THEN \ -- uDVDlo uDVDhi uDIVlo
200 PUSHM IP,T \ save IP,S,T
202 UM/MOD \ -- uREMlo uQUOTlo
204 POPM T,IP \ restore T,S,IP
205 CMP #0,T \ T=rem_sign
210 XOR S,T \ S=divisor T=quot_sign
211 CMP #0,T \ -- n3 u4 T=quot_sign
217 THEN \ -- n3 n4 S=divisor
222 \ https://forth-standard.org/standard/core/NEGATE
223 \ C NEGATE x1 -- x2 two's complement
229 \ https://forth-standard.org/standard/core/ABS
230 \ C ABS n1 -- +n2 absolute value
238 \ https://forth-standard.org/standard/core/FMDivMOD
239 \ FM/MOD d1 n1 -- r q floored signed div'n
242 HI2LO \ -- remainder quotient S=divisor
243 CMP #0,0(PSP) \ remainder <> 0 ?
245 CMP #1,TOS \ quotient < 1 ?
247 ADD S,0(PSP) \ add divisor to remainder
248 SUB #1,TOS \ decrement quotient
256 \ https://forth-standard.org/standard/core/Times
257 \ * n1 n2 -- n3 signed multiply
263 \ https://forth-standard.org/standard/core/DivMOD
264 \ /MOD n1 n2 -- r3 q4 signed division
270 \ https://forth-standard.org/standard/core/Div
271 \ / n1 n2 -- n3 signed quotient
273 >R DUP 0< R> FM/MOD NIP
277 \ https://forth-standard.org/standard/core/MOD
278 \ MOD n1 n2 -- n3 signed remainder
280 >R DUP 0< R> FM/MOD DROP
284 \ https://forth-standard.org/standard/core/TimesDivMOD
285 \ */MOD n1 n2 n3 -- r4 q5 signed mult/div
291 \ https://forth-standard.org/standard/core/TimesDiv
292 \ */ 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.
309 \ https://forth-standard.org/standard/core/TwoFetch
310 \ 2@ a-addr -- x1 x2 fetch 2 cells ; the lower address will appear on top of stack
319 \ https://forth-standard.org/standard/core/TwoStore
320 \ 2! x1 x2 a-addr -- store 2 cells ; the top of stack is stored at the lower adr
329 \ https://forth-standard.org/standard/core/TwoDUP
330 \ 2DUP x1 x2 -- x1 x2 x1 x2 dup top 2 cells
332 SUB #4,PSP \ -- x1 x x x2
333 MOV TOS,2(PSP) \ -- x1 x2 x x2
334 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x2
339 \ https://forth-standard.org/standard/core/TwoDROP
340 \ 2DROP x1 x2 -- drop 2 cells
348 \ https://forth-standard.org/standard/core/TwoSWAP
349 \ 2SWAP x1 x2 x3 x4 -- x3 x4 x1 x2
351 MOV @PSP,W \ -- x1 x2 x3 x4 W=x3
352 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x4
353 MOV W,4(PSP) \ -- x3 x2 x1 x4
354 MOV TOS,W \ -- x3 x2 x1 x4 W=x4
355 MOV 2(PSP),TOS \ -- x3 x2 x1 x2 W=x4
356 MOV W,2(PSP) \ -- x3 x4 x1 x2
361 \ https://forth-standard.org/standard/core/TwoOVER
362 \ 2OVER x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2
364 SUB #4,PSP \ -- x1 x2 x3 x x x4
365 MOV TOS,2(PSP) \ -- x1 x2 x3 x4 x x4
366 MOV 8(PSP),0(PSP) \ -- x1 x2 x3 x4 x1 x4
367 MOV 6(PSP),TOS \ -- x1 x2 x3 x4 x1 x2
372 \ ----------------------------------------------------------------------
373 \ ALIGNMENT OPERATORS
374 \ ----------------------------------------------------------------------
376 \ https://forth-standard.org/standard/core/ALIGNED
377 \ ALIGNED addr -- a-addr align given addr
385 \ https://forth-standard.org/standard/core/ALIGN
386 \ ALIGN -- align HERE
394 \ ---------------------
395 \ PORTABILITY OPERATORS
396 \ ---------------------
398 \ https://forth-standard.org/standard/core/CHARS
399 \ CHARS n1 -- n2 chars->adrs units
405 \ https://forth-standard.org/standard/core/CHARPlus
406 \ CHAR+ c-addr1 -- c-addr2 add char size
413 \ https://forth-standard.org/standard/core/CELLS
414 \ CELLS n1 -- n2 cells->adrs units
421 \ https://forth-standard.org/standard/core/CELLPlus
422 \ CELL+ a-addr1 -- a-addr2 add cell size
428 \ ---------------------------
429 \ BLOCK AND STRING COMPLEMENT
430 \ ---------------------------
432 \ https://forth-standard.org/standard/core/CHAR
433 \ CHAR -- char parse ASCII character
438 \ https://forth-standard.org/standard/core/BracketCHAR
439 \ [CHAR] -- compile character literal
446 \ https://forth-standard.org/standard/core/PlusStore
447 \ +! n/u a-addr -- add n/u to memory
455 \ https://forth-standard.org/standard/core/FILL
456 \ FILL c-addr u char -- fill memory with char
459 MOV @PSP+,W \ address
463 MOV.B TOS,0(W) \ store char in memory
468 MOV @PSP+,TOS \ empties stack
473 \ --------------------
474 \ INTERPRET COMPLEMENT
475 \ --------------------
477 \ https://forth-standard.org/standard/core/HEX
484 \ https://forth-standard.org/standard/core/DECIMAL
491 \ https://forth-standard.org/standard/core/p
492 \ ( -- skip input until char ) or EOL
498 [DEFINED] CAPS_ON [IF]
500 \ https://forth-standard.org/standard/core/Dotp
501 \ .( -- type comment immediatly.
510 \ https://forth-standard.org/standard/core/Dotp
511 \ .( -- type comment immediatly.
520 \ https://forth-standard.org/standard/core/SOURCE
521 \ SOURCE -- adr u of current input buffer
526 MOV &SOURCE_ADR,0(PSP)
531 \ https://forth-standard.org/standard/core/toBODY
532 \ >BODY -- PFA leave PFA of created word
539 \ https://forth-standard.org/standard/core/toIN
540 \ C >IN -- a-addr holds offset in input stream
546 \ https://forth-standard.org/standard/core/PAD