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/INVERT
26 \ INVERT x1 -- x2 bitwise inversion
33 \ https://forth-standard.org/standard/core/LSHIFT
34 \ LSHIFT x1 u -- x2 logical L shift u places
37 AND #$1F,TOS \ no need to shift more than 16
47 \ https://forth-standard.org/standard/core/RSHIFT
48 \ RSHIFT x1 u -- x2 logical R7 shift u places
51 AND #$1F,TOS \ no need to shift more than 16
53 BEGIN BIC #C,SR \ Clr Carry
62 \ https://forth-standard.org/standard/core/OnePlus
63 \ 1+ n1/u1 -- n2/u2 add 1 to TOS
70 \ https://forth-standard.org/standard/core/OneMinus
71 \ 1- n1/u1 -- n2/u2 subtract 1 from TOS
79 \ https://forth-standard.org/standard/core/MAX
80 \ MAX n1 n2 -- n3 signed maximum
89 \ https://forth-standard.org/standard/core/MIN
90 \ MIN n1 n2 -- n3 signed minimum
100 \ https://forth-standard.org/standard/core/TwoTimes
101 \ 2* x1 -- x2 arithmetic left shift
108 \ https://forth-standard.org/standard/core/TwoDiv
109 \ 2/ x1 -- x2 arithmetic right shift
116 \ --------------------
117 \ ARITHMETIC OPERATORS
118 \ --------------------
120 $1A04 C@ $EF > [IF] ; test tag value MSP430FR413x subfamily without hardware_MPY
122 \ https://forth-standard.org/standard/core/MTimes
123 \ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
128 XOR #-1,0(PSP) \ n1 --> u1
131 XOR TOS,S \ S contains sign of result
132 CMP #0,TOS \ n2 > -1 ?
134 XOR #-1,TOS \ n2 --> u2
137 PUSHM IP,S \ UMSTAR use S,T,W,X,Y
142 CMP #0,S \ sign of result > -1 ?
144 XOR #-1,0(PSP) \ ud --> d
152 [ELSE] ; MSP430FRxxxx with hardware_MPY
154 \ https://forth-standard.org/standard/core/UMTimes
155 \ UM* u1 u2 -- udlo udhi unsigned 16x16->32 mult.
157 MOV @PSP,&MPY \ Load 1st operand for unsigned multiplication
158 BW1 MOV TOS,&OP2 \ Load 2nd operand
159 MOV &RES0,0(PSP) \ low result on stack
160 MOV &RES1,TOS \ high result in TOS
165 \ https://forth-standard.org/standard/core/MTimes
166 \ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
168 MOV @PSP,&MPYS \ Load 1st operand for signed multiplication
175 \ https://forth-standard.org/standard/core/UMDivMOD
176 \ UM/MOD udlo|udhi u1 -- r q unsigned 32/16->16
178 CALL #MU/MOD \ -- REMlo QUOTlo QUOThi
184 \ https://forth-standard.org/standard/core/SMDivREM
185 \ SM/REM d1lo d1hi n2 -- r3 q4 symmetric signed div
187 MOV TOS,S \ S=divisor
188 MOV @PSP,T \ T=dividend_sign==>rem_sign
189 CMP #0,TOS \ n2 >= 0 ?
192 ADD #1,TOS \ -- d1 u2
194 CMP #0,0(PSP) \ d1hi >= 0 ?
196 XOR #-1,2(PSP) \ d1lo
197 XOR #-1,0(PSP) \ d1hi
198 ADD #1,2(PSP) \ d1lo+1
199 ADDC #0,0(PSP) \ d1hi+C
200 THEN \ -- uDVDlo uDVDhi uDIVlo
202 CALL #MU/MOD \ -- uREMlo uQUOTlo uQUOThi
203 MOV @PSP+,TOS \ -- uREMlo uQUOTlo
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
215 THEN \ -- n3 n4 S=divisor
220 \ https://forth-standard.org/standard/core/FMDivMOD
221 \ FM/MOD d1 n1 -- r q floored signed div'n
224 HI2LO \ -- remainder quotient S=divisor
225 CMP #0,0(PSP) \ remainder <> 0 ?
227 CMP #1,TOS \ quotient < 1 ?
229 ADD S,0(PSP) \ add divisor to remainder
230 SUB #1,TOS \ decrement quotient
238 \ https://forth-standard.org/standard/core/Times
239 \ * n1 n2 -- n3 signed multiply
245 \ https://forth-standard.org/standard/core/DivMOD
246 \ /MOD n1 n2 -- r3 q4 signed division
252 \ https://forth-standard.org/standard/core/Div
253 \ / n1 n2 -- n3 signed quotient
255 >R DUP 0< R> FM/MOD NIP
259 \ https://forth-standard.org/standard/core/MOD
260 \ MOD n1 n2 -- n3 signed remainder
262 >R DUP 0< R> FM/MOD DROP
266 \ https://forth-standard.org/standard/core/TimesDivMOD
267 \ */MOD n1 n2 n3 -- r4 q5 signed mult/div
273 \ https://forth-standard.org/standard/core/TimesDiv
274 \ */ n1 n2 n3 -- n4 n1*n2/q3
280 \ ----------------------------------------------------------------------
282 \ ----------------------------------------------------------------------
284 \ https://forth-standard.org/standard/core/StoD
285 \ S>D n -- d single -> double prec.
291 \ https://forth-standard.org/standard/core/TwoFetch
292 \ 2@ a-addr -- x1 x2 fetch 2 cells ; the lower address will appear on top of stack
301 \ https://forth-standard.org/standard/core/TwoStore
302 \ 2! x1 x2 a-addr -- store 2 cells ; the top of stack is stored at the lower adr
311 \ https://forth-standard.org/standard/core/TwoDUP
312 \ 2DUP x1 x2 -- x1 x2 x1 x2 dup top 2 cells
314 SUB #4,PSP \ -- x1 x x x2
315 MOV TOS,2(PSP) \ -- x1 x2 x x2
316 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x2
321 \ https://forth-standard.org/standard/core/TwoDROP
322 \ 2DROP x1 x2 -- drop 2 cells
330 \ https://forth-standard.org/standard/core/TwoSWAP
331 \ 2SWAP x1 x2 x3 x4 -- x3 x4 x1 x2
333 MOV @PSP,W \ -- x1 x2 x3 x4 W=x3
334 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x4
335 MOV W,4(PSP) \ -- x3 x2 x1 x4
336 MOV TOS,W \ -- x3 x2 x1 x4 W=x4
337 MOV 2(PSP),TOS \ -- x3 x2 x1 x2 W=x4
338 MOV W,2(PSP) \ -- x3 x4 x1 x2
343 \ https://forth-standard.org/standard/core/TwoOVER
344 \ 2OVER x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2
346 SUB #4,PSP \ -- x1 x2 x3 x x x4
347 MOV TOS,2(PSP) \ -- x1 x2 x3 x4 x x4
348 MOV 8(PSP),0(PSP) \ -- x1 x2 x3 x4 x1 x4
349 MOV 6(PSP),TOS \ -- x1 x2 x3 x4 x1 x2
355 \ ----------------------------------------------------------------------
356 \ ALIGNMENT OPERATORS
357 \ ----------------------------------------------------------------------
359 \ https://forth-standard.org/standard/core/ALIGNED
360 \ ALIGNED addr -- a-addr align given addr
368 \ https://forth-standard.org/standard/core/ALIGN
369 \ ALIGN -- align HERE
377 \ ---------------------
378 \ PORTABILITY OPERATORS
379 \ ---------------------
381 \ https://forth-standard.org/standard/core/CHARS
382 \ CHARS n1 -- n2 chars->adrs units
388 \ https://forth-standard.org/standard/core/CHARPlus
389 \ CHAR+ c-addr1 -- c-addr2 add char size
396 \ https://forth-standard.org/standard/core/CELLS
397 \ CELLS n1 -- n2 cells->adrs units
404 \ https://forth-standard.org/standard/core/CELLPlus
405 \ CELL+ a-addr1 -- a-addr2 add cell size
411 \ ---------------------------
412 \ BLOCK AND STRING COMPLEMENT
413 \ ---------------------------
415 \ https://forth-standard.org/standard/core/CHAR
416 \ CHAR -- char parse ASCII character
421 \ https://forth-standard.org/standard/core/BracketCHAR
422 \ [CHAR] -- compile character literal
429 \ https://forth-standard.org/standard/core/PlusStore
430 \ +! n/u a-addr -- add n/u to memory
439 \ https://forth-standard.org/standard/core/FILL
440 \ FILL c-addr u char -- fill memory with char
443 MOV @PSP+,W \ address
447 MOV.B TOS,0(W) \ store char in memory
452 MOV @PSP+,TOS \ empties stack
457 \ --------------------
458 \ INTERPRET COMPLEMENT
459 \ --------------------
461 \ https://forth-standard.org/standard/core/HEX
468 \ https://forth-standard.org/standard/core/DECIMAL
475 \ https://forth-standard.org/standard/core/p
476 \ ( -- skip input until char ) or EOL
482 [DEFINED] CAPS_ON [IF]
484 \ https://forth-standard.org/standard/core/Dotp
485 \ .( -- type comment immediatly.
494 \ https://forth-standard.org/standard/core/Dotp
495 \ .( -- type comment immediatly.
504 \ https://forth-standard.org/standard/core/SOURCE
505 \ SOURCE -- adr u of current input buffer
510 MOV &SOURCE_ADR,0(PSP)
515 \ https://forth-standard.org/standard/core/toBODY
516 \ >BODY -- PFA leave PFA of created word