1 \ -*- coding: utf-8 -*-
3 ; -----------------------------------------------------
4 ; ANS_COMP.f words complement to pass CORETEST.4TH
5 ; -----------------------------------------------------
7 \ to see kernel options, download FastForthSpecs.f
8 \ FastForth kernel options: MSP430ASSEMBLER, CONDCOMP
10 \ TARGET Current Selection
11 \ (used by preprocessor GEMA to load the pattern: \config\gema\TARGET.pat)
12 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
13 \ MSP_EXP430FR2433 MSP_EXP430FR4133 MSP_EXP430FR2355 CHIPSTICK_FR2433
16 \ rDODOES to rEXIT must be saved before use and restored after
17 \ scratch registers Y to S are free for use
18 \ under interrupt, IP is free for use
20 \ PUSHM order : PSP,TOS, IP, S, T, W, X, Y, rEXIT, rDOVAR, rDOCON, rDODOES
21 \ example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
23 \ POPM order : rDODOES, rDOCON, rDOVAR, rEXIT, Y, X, W, T, S, IP,TOS,PSP
24 \ example : POPM #6,IP pulls Y,X,W,T,S,IP registers from return stack
26 \ FORTH conditionnals: unary{ 0= 0< 0> }, binary{ = < > U< }
28 \ ASSEMBLER conditionnal usage with IF UNTIL WHILE S< S>= U< U>= 0= 0<> 0>=
29 \ ASSEMBLER conditionnal usage with ?GOTO S< S>= U< U>= 0= 0<> 0<
31 [UNDEFINED] {ANS_COMP} [IF]
37 \ https://forth-standard.org/standard/core/VALUE
38 \ ( x "<spaces>name" -- ) define a Forth VALUE
39 \ Skip leading space delimiters. Parse name delimited by a space.
40 \ Create a definition for name with the execution semantics defined below,
41 \ with an initial value equal to x.
43 \ name Execution: ( -- x )
44 \ Place x on the stack. The value of x is that given when name was created,
45 \ until the phrase x TO name is executed, causing a new value of x to be assigned to name.
47 \ TO name Run-time: ( x -- )
48 \ Assign the value x to name.
50 [UNDEFINED] VARIABLE [IF]
51 \ https://forth-standard.org/standard/core/VARIABLE
52 \ VARIABLE <name> -- define a Forth VARIABLE
58 MOV #DOVAR,-4(W) \ CFA = DOVAR
64 [UNDEFINED] CONSTANT [IF]
65 \ https://forth-standard.org/standard/core/CONSTANT
66 \ CONSTANT <name> n -- define a Forth CONSTANT
71 MOV #DOCON,-4(W) \ CFA = DOCON
72 MOV TOS,-2(W) \ PFA = n
78 \ https://forth-standard.org/standard/core/STATE
79 \ STATE -- a-addr holds compiler state
80 STATEADR CONSTANT STATE
83 \ https://forth-standard.org/standard/core/BASE
84 \ BASE -- a-addr holds conversion radix
89 \ https://forth-standard.org/standard/core/toIN
90 \ C >IN -- a-addr holds offset in input stream
95 \ https://forth-standard.org/standard/core/PAD
101 \ https://forth-standard.org/standard/core/BL
102 \ BL -- char an ASCII space
106 [UNDEFINED] SPACE [IF]
107 \ https://forth-standard.org/standard/core/SPACE
108 \ SPACE -- output a space
113 [UNDEFINED] SPACES [IF]
114 \ https://forth-standard.org/standard/core/SPACES
115 \ SPACES n -- output n spaces
129 MOV @PSP+,TOS \ -- drop n
135 \ \ https://forth-standard.org/standard/core/VALUE
136 \ : VALUE \ x "<spaces>name" --
141 \ BIT #UF10,SR \ see TO
149 \ \ https://forth-standard.org/standard/core/TO
150 \ \ TO name Run-time: ( x -- )
151 \ \ Assign the value x to named VALUE.
157 \ https://forth-standard.org/standard/core/StoD
158 \ S>D n -- d single -> double prec.
164 \ https://forth-standard.org/standard/core/NIP
165 \ NIP x1 x2 -- x2 Drop the first item below the top of stack
173 \ https://forth-standard.org/standard/core/CFetch
174 \ C@ c-addr -- char fetch char from memory
182 \ https://forth-standard.org/standard/core/CStore
183 \ C! char c-addr -- store char in memory
185 MOV.B @PSP+,0(TOS) \ 4
193 \ https://forth-standard.org/standard/core/CComma
194 \ C, char -- append char
205 \ https://forth-standard.org/standard/core/AND
206 \ C AND x1 x2 -- x3 logical AND
214 \ https://forth-standard.org/standard/core/OR
215 \ C OR x1 x2 -- x3 logical OR
223 \ https://forth-standard.org/standard/core/XOR
224 \ C XOR x1 x2 -- x3 logical XOR
232 \ https://forth-standard.org/standard/core/Plus
233 \ + n1/u1 n2/u2 -- n3/u3 add n1+n2
240 \ https://forth-standard.org/standard/core/INVERT
241 \ INVERT x1 -- x2 bitwise inversion
247 \ https://forth-standard.org/standard/core/less
248 \ < n1 n2 -- flag test n1<n2, signed
250 SUB @PSP+,TOS \ 1 TOS=n2-n1
251 S< ?GOTO FW1 \ 2 signed
253 BW1 MOV #-1,TOS \ 1 flag Z = 0
258 \ https://forth-standard.org/standard/core/more
259 \ > n1 n2 -- flag test n1>n2, signed
261 SUB @PSP+,TOS \ 2 TOS=n2-n1
262 S< ?GOTO BW1 \ 2 --> +5
263 FW1 AND #0,TOS \ 1 flag Z = 1
267 \ https://forth-standard.org/standard/core/LSHIFT
268 \ LSHIFT x1 u -- x2 logical L shift u places
271 AND #$1F,TOS \ no need to shift more than 16
280 \ https://forth-standard.org/standard/core/RSHIFT
281 \ RSHIFT x1 u -- x2 logical R7 shift u places
284 AND #$1F,TOS \ no need to shift more than 16
286 BEGIN BIC #C,SR \ Clr Carry
295 \ https://forth-standard.org/standard/core/MAX
296 \ MAX n1 n2 -- n3 signed maximum
304 \ https://forth-standard.org/standard/core/MIN
305 \ MIN n1 n2 -- n3 signed minimum
314 \ https://forth-standard.org/standard/core/TwoTimes
315 \ 2* x1 -- x2 arithmetic left shift
321 \ https://forth-standard.org/standard/core/TwoDiv
322 \ 2/ x1 -- x2 arithmetic right shift
328 \ --------------------
329 \ ARITHMETIC OPERATORS
330 \ --------------------
331 TLV_ORG 4 + @ $81F3 U<
332 $81EF TLV_ORG 4 + @ U<
333 = [IF] ; MSP430FR413x subfamily without hardware_MPY
335 \ https://forth-standard.org/standard/core/MTimes
336 \ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
341 XOR #-1,0(PSP) \ n1 --> u1
344 XOR TOS,S \ S contains sign of result
345 CMP #0,TOS \ n2 > -1 ?
347 XOR #-1,TOS \ n2 --> u2
350 PUSHM #2,IP \ UMSTAR use S,T,W,X,Y
354 POPM #2,IP \ pop S,IP
355 CMP #0,S \ sign of result > -1 ?
357 XOR #-1,0(PSP) \ ud --> d
365 [ELSE] ; MSP430FRxxxx with hardware_MPY
367 \ https://forth-standard.org/standard/core/UMTimes
368 \ UM* u1 u2 -- udlo udhi unsigned 16x16->32 mult.
370 MOV @PSP,&MPY \ Load 1st operand for unsigned multiplication
371 BW1 MOV TOS,&OP2 \ Load 2nd operand
372 MOV &RES0,0(PSP) \ low result on stack
373 MOV &RES1,TOS \ high result in TOS
377 \ https://forth-standard.org/standard/core/MTimes
378 \ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
380 MOV @PSP,&MPYS \ Load 1st operand for signed multiplication
386 \ https://forth-standard.org/standard/core/UMDivMOD
387 \ UM/MOD udlo|udhi u1 -- r q unsigned 32/16->r16 q16
390 MOV #<#,X \ X = addr of <#
391 ADD #8,X \ X = addr of MUSMOD
392 MOV X,PC \ execute MUSMOD then RET to DROP
395 \ https://forth-standard.org/standard/core/SMDivREM
396 \ SM/REM DVDlo DVDhi DIVlo -- r3 q4 symmetric signed div
399 MOV @PSP,T \ T=DVD_sign==>rem_sign
400 CMP #0,TOS \ n2 >= 0 ?
403 ADD #1,TOS \ -- d1 u2
405 CMP #0,0(PSP) \ d1hi >= 0 ?
407 XOR #-1,2(PSP) \ d1lo
408 XOR #-1,0(PSP) \ d1hi
409 ADD #1,2(PSP) \ d1lo+1
410 ADDC #0,0(PSP) \ d1hi+C
411 THEN \ -- uDVDlo uDVDhi uDIVlo
412 PUSHM #3,IP \ save IP,S,T
414 UM/MOD \ -- uREMlo uQUOTlo
416 POPM #3,IP \ restore T,S,IP
417 CMP #0,T \ T=rem_sign
422 XOR S,T \ S=divisor T=quot_sign
423 CMP #0,T \ -- n3 u4 T=quot_sign
429 THEN \ -- n3 n4 S=divisor
433 \ https://forth-standard.org/standard/core/NEGATE
434 \ C NEGATE x1 -- x2 two's complement
439 \ https://forth-standard.org/standard/core/ABS
440 \ C ABS n1 -- +n2 absolute value
447 \ https://forth-standard.org/standard/core/FMDivMOD
448 \ FM/MOD d1 n1 -- r q floored signed div'n
451 HI2LO \ -- remainder quotient S=divisor
452 CMP #0,0(PSP) \ remainder <> 0 ?
454 CMP #1,TOS \ quotient < 1 ?
456 ADD S,0(PSP) \ add divisor to remainder
457 SUB #1,TOS \ decrement quotient
464 \ https://forth-standard.org/standard/core/Times
465 \ * n1 n2 -- n3 signed multiply
470 \ https://forth-standard.org/standard/core/DivMOD
471 \ /MOD n1 n2 -- r3 q4 signed division
476 \ https://forth-standard.org/standard/core/Div
477 \ / n1 n2 -- n3 signed quotient
479 >R DUP 0< R> FM/MOD NIP
482 \ https://forth-standard.org/standard/core/MOD
483 \ MOD n1 n2 -- n3 signed remainder
485 >R DUP 0< R> FM/MOD DROP
488 \ https://forth-standard.org/standard/core/TimesDivMOD
489 \ */MOD n1 n2 n3 -- r4 q5 signed mult/div
494 \ https://forth-standard.org/standard/core/TimesDiv
495 \ */ n1 n2 n3 -- n4 n1*n2/q3
500 \ -------------------------------------------------------------------------------
502 \ -------------------------------------------------------------------------------
504 [UNDEFINED] OVER [IF]
505 \ https://forth-standard.org/standard/core/OVER
506 \ OVER x1 x2 -- x1 x2 x1
508 MOV TOS,-2(PSP) \ 3 -- x1 (x2) x2
509 MOV @PSP,TOS \ 2 -- x1 (x2) x1
510 SUB #2,PSP \ 1 -- x1 x2 x1
515 \ https://forth-standard.org/standard/core/ROT
516 \ ROT x1 x2 x3 -- x2 x3 x1
518 MOV @PSP,W \ 2 fetch x2
519 MOV TOS,0(PSP) \ 3 store x3
520 MOV 2(PSP),TOS \ 3 fetch x1
521 MOV W,2(PSP) \ 3 store x2
525 \ https://forth-standard.org/standard/core/RFetch
526 \ R@ -- x R: x -- x fetch from return stack
534 \ ----------------------------------------------------------------------
536 \ ----------------------------------------------------------------------
538 [UNDEFINED] {DOUBLE} [IF]
540 \ https://forth-standard.org/standard/core/TwoFetch
541 \ 2@ a-addr -- x1 x2 fetch 2 cells ; the lower address will appear on top of stack
549 \ https://forth-standard.org/standard/core/TwoStore
550 \ 2! x1 x2 a-addr -- store 2 cells ; the top of stack is stored at the lower adr
558 \ \ https://forth-standard.org/standard/double/TwoVALUE
559 \ : 2VALUE \ x1 x2 "<spaces>name" --
560 \ CREATE , , \ compile Shi then Flo
564 \ BIT #UF10,SR \see TO
570 \ https://forth-standard.org/standard/core/TwoDROP
571 \ 2DROP x1 x2 -- drop 2 cells
578 \ https://forth-standard.org/standard/core/TwoSWAP
579 \ 2SWAP x1 x2 x3 x4 -- x3 x4 x1 x2
581 MOV @PSP,W \ -- x1 x2 x3 x4 W=x3
582 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x4
583 MOV W,4(PSP) \ -- x3 x2 x1 x4
584 MOV TOS,W \ -- x3 x2 x1 x4 W=x4
585 MOV 2(PSP),TOS \ -- x3 x2 x1 x2 W=x4
586 MOV W,2(PSP) \ -- x3 x4 x1 x2
590 \ https://forth-standard.org/standard/core/TwoOVER
591 \ 2OVER x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2
593 SUB #4,PSP \ -- x1 x2 x3 x x x4
594 MOV TOS,2(PSP) \ -- x1 x2 x3 x4 x x4
595 MOV 8(PSP),0(PSP) \ -- x1 x2 x3 x4 x1 x4
596 MOV 6(PSP),TOS \ -- x1 x2 x3 x4 x1 x2
602 \ ----------------------------------------------------------------------
603 \ ALIGNMENT OPERATORS
604 \ ----------------------------------------------------------------------
605 \ https://forth-standard.org/standard/core/ALIGNED
606 \ ALIGNED addr -- a-addr align given addr
613 \ https://forth-standard.org/standard/core/ALIGN
614 \ ALIGN -- align HERE
621 \ ---------------------
622 \ PORTABILITY OPERATORS
623 \ ---------------------
624 \ https://forth-standard.org/standard/core/CHARS
625 \ CHARS n1 -- n2 chars->adrs units
630 \ https://forth-standard.org/standard/core/CHARPlus
631 \ CHAR+ c-addr1 -- c-addr2 add char size
637 \ https://forth-standard.org/standard/core/CELLS
638 \ CELLS n1 -- n2 cells->adrs units
644 \ https://forth-standard.org/standard/core/CELLPlus
645 \ CELL+ a-addr1 -- a-addr2 add cell size
651 \ ---------------------------
652 \ BLOCK AND STRING COMPLEMENT
653 \ ---------------------------
655 \ https://forth-standard.org/standard/core/CHAR
656 \ CHAR -- char parse ASCII character
661 \ https://forth-standard.org/standard/core/BracketCHAR
662 \ [CHAR] -- compile character literal
664 CHAR POSTPONE LITERAL
667 \ https://forth-standard.org/standard/core/PlusStore
668 \ +! n/u a-addr -- add n/u to memory
675 \ https://forth-standard.org/standard/core/FILL
676 \ FILL c-addr u char -- fill memory with char
679 MOV @PSP+,W \ address
683 MOV.B TOS,0(W) \ store char in memory
688 MOV @PSP+,TOS \ empties stack
692 \ --------------------
693 \ INTERPRET COMPLEMENT
694 \ --------------------
696 \ https://forth-standard.org/standard/core/HEX
702 \ https://forth-standard.org/standard/core/DECIMAL
708 \ https://forth-standard.org/standard/core/p
709 \ ( -- skip input until char ) or EOL
714 \ https://forth-standard.org/standard/core/Dotp
715 \ .( -- type comment immediatly.
717 MOV #0,&CAPS \ CAPS OFF
724 \ https://forth-standard.org/standard/core/J
725 \ J -- n R: 4*sys -- 4*sys
726 \ C get the second loop index
735 \ https://forth-standard.org/standard/core/UNLOOP
736 \ UNLOOP -- R: sys1 sys2 -- drop loop parms
742 \ https://forth-standard.org/standard/core/LEAVE
743 \ LEAVE -- L: -- adrs
745 MOV &DP,W \ compile three words
746 MOV #UNLOOP,0(W) \ [HERE] = UNLOOP
747 MOV #.,2(W) \ DOT + 8 = BRAN
748 ADD #8,2(W) \ [HERE+2] = BRAN
749 ADD #6,&DP \ [HERE+4] = After LOOP adr
753 MOV W,0(X) \ leave HERE+4 on LEAVEPTR stack
757 \ https://forth-standard.org/standard/core/RECURSE
758 \ C RECURSE -- recurse to current definition (compile current definition)
766 \ https://forth-standard.org/standard/core/SOURCE
767 \ SOURCE -- adr u of current input buffer
772 MOV &SOURCE_ORG,0(PSP)