1 \ -*- coding: utf-8 -*-
3 \ TARGET SELECTION ( = the name of \INC\target.pat file without the extension)
4 \ (used by preprocessor GEMA to load the pattern: \inc\TARGET.pat)
5 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
6 \ MSP_EXP430FR4133 CHIPSTICK_FR2433 MSP_EXP430FR2433 MSP_EXP430FR2355
10 \ from scite editor : copy your target selection in (shift+F8) parameter 1:
14 \ drag and drop this file onto SendSourceFileToTarget.bat
15 \ then select your TARGET when asked.
19 \ rDODOES to rEXIT must be saved before use and restored after
20 \ scratch registers Y to S are free for use
21 \ under interrupt, IP is free for use
23 \ PUSHM order : PSP,TOS, IP, S, T, W, X, Y, rEXIT, rDOVAR, rDOCON, rDODOES
24 \ example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
26 \ POPM order : rDODOES, rDOCON, rDOVAR, rEXIT, Y, X, W, T, S, IP,TOS,PSP
27 \ example : POPM #6,IP pulls Y,X,W,T,S,IP registers from return stack
29 \ FORTH conditionnals: unary{ 0= 0< 0> }, binary{ = < > U< }
31 \ ASSEMBLER conditionnal usage with IF UNTIL WHILE S< S>= U< U>= 0= 0<> 0>=
32 \ ASSEMBLER conditionnal usage with ?GOTO S< S>= U< U>= 0= 0<> 0<
38 SUB #401,TOS \ FastForth V4.1
40 'CR' EMIT \ return to column 1, no 'LF'
41 ABORT" FastForth V4.1 please!"
47 \ BC! pattern @ -- Bits Clear in @
56 \ BS! pattern @ -- Bits Set in @
64 \ =============================================================================
65 $8000 KERNEL_ADDON BC! \ uncomment to select SYMMETRIC division
66 \ $8000 KERNEL_ADDON BS! \ uncomment to select FLOORED division
67 \ =============================================================================
69 RST_RET \ remove all above before CORE_ANS downloading
71 ; ----------------------------------
73 ; ----------------------------------
75 \ words complement to pass CORETEST.4TH
78 [IF] {CORE_ANS} [THEN] \ if already defined removes it before.
80 [UNDEFINED] {CORE_ANS} [IF]
83 [UNDEFINED] ABORT [IF]
84 \ https://forth-standard.org/standard/core/ABORT
85 \ Empty the data stack and perform the function of QUIT
87 MOV #ABORT,PC \ addr defined in MSP430FRxxxx.pat
92 \ https://forth-standard.org/standard/core/QUIT
93 \ Empty the return stack, store zero in SOURCE-ID if it is present,
94 \ make the user input device the input source, and enter interpretation state.
95 \ Do not display a message. Repeat the following:
96 \ Accept a line from the input source into the input buffer, set >IN to zero, and interpret.
97 \ Display the implementation-defined system prompt if in interpretation state,
98 \ all processing has been completed,
99 \ and no ambiguous condition exists.
101 MOV #QUIT,PC \ addr defined in MSP430FRxxxx.pat
105 [UNDEFINED] HERE [IF]
106 \ https://forth-standard.org/standard/core/HERE
107 \ HERE -- addr addr is the data-space pointer.
109 MOV #BEGIN,PC \ execute ASM BEGIN
114 \ https://forth-standard.org/standard/core/Plus
115 \ + n1/u1 n2/u2 -- n3/u3 add n1+n2
123 \ https://forth-standard.org/standard/core/Minus
124 \ - n1/u1 n2/u2 -- n3/u3 n3 = n1-n2
126 SUB @PSP+,TOS \ 2 -- n2-n1 ( = -n3)
128 ADD #1,TOS \ 1 -- n3 = -(n2-n1) = n1-n2
133 [UNDEFINED] DUP [IF] \ define DUP and ?DUP
135 \ https://forth-standard.org/standard/core/DUP
136 \ DUP x -- x x duplicate top of stack
138 BW1 SUB #2,PSP \ 2 push old TOS..
139 MOV TOS,0(PSP) \ 3 ..onto stack
143 \ https://forth-standard.org/standard/core/qDUP
144 \ ?DUP x -- 0 | x x DUP if nonzero
146 CMP #0,TOS \ 2 test for TOS nonzero
152 [UNDEFINED] EXIT [IF]
153 \ https://forth-standard.org/standard/core/EXIT
154 \ EXIT -- exit a colon definition
156 MOV @RSP+,IP \ 2 pop previous IP (or next PC) from return stack
157 MOV @IP+,PC \ 4 = NEXT
161 [UNDEFINED] DEPTH [IF]
162 \ https://forth-standard.org/standard/core/DEPTH
163 \ DEPTH -- +n number of items on stack, must leave 0 if stack empty
167 SUB PSP,TOS \ PSP-S0--> TOS
168 RRA TOS \ TOS/2 --> TOS
169 SUB #2,PSP \ post decrement stack...
174 [UNDEFINED] SWAP [IF]
175 \ https://forth-standard.org/standard/core/SWAP
176 \ SWAP x1 x2 -- x2 x1 swap top two items
185 [UNDEFINED] DROP [IF]
186 \ https://forth-standard.org/standard/core/DROP
187 \ DROP x -- drop top of stack
194 [UNDEFINED] OVER [IF]
195 \ https://forth-standard.org/standard/core/OVER
196 \ OVER x1 x2 -- x1 x2 x1
198 MOV TOS,-2(PSP) \ 3 -- x1 (x2) x2
199 MOV @PSP,TOS \ 2 -- x1 (x2) x1
200 SUB #2,PSP \ 1 -- x1 x2 x1
206 \ https://forth-standard.org/standard/core/NIP
207 \ NIP x1 x2 -- x2 Drop the first item below the top of stack
215 \ https://forth-standard.org/standard/core/toR
216 \ >R x -- R: -- x push to return stack
225 \ https://forth-standard.org/standard/core/Rfrom
226 \ R> -- x R: x -- pop from return stack
236 \ https://forth-standard.org/standard/core/Fetch
237 \ C@ c-addr -- char fetch char from memory
245 \ https://forth-standard.org/standard/core/CStore
246 \ C! char c-addr -- store char in memory
248 MOV.B @PSP+,0(TOS) \ 4
256 \ https://forth-standard.org/standard/core/CComma
257 \ C, char -- append char
268 \ https://forth-standard.org/standard/core/ZeroEqual
269 \ 0= n/u -- flag return true if TOS=0
271 SUB #1,TOS \ 1 borrow (clear cy) if TOS was 0
272 SUBC TOS,TOS \ 1 TOS=-1 if borrow was set
278 \ https://forth-standard.org/standard/core/Zerone
279 \ 0<> n/u -- flag return true if TOS<>0
281 SUB #1,TOS \ 1 borrow (clear cy) if TOS was 0
282 SUBC TOS,TOS \ 1 TOS=-1 if borrow was set
289 \ https://forth-standard.org/standard/core/Zeroless
290 \ 0< n -- flag true if TOS negative
292 ADD TOS,TOS \ 1 set carry if TOS negative
293 SUBC TOS,TOS \ 1 TOS=-1 if carry was clear
294 XOR #-1,TOS \ 1 TOS=-1 if carry was set
300 \ https://forth-standard.org/standard/core/StoD
301 \ S>D n -- d single -> double prec.
308 \ https://forth-standard.org/standard/core/Equal
309 \ = x1 x2 -- flag test x1=x2
312 SUB #1,TOS \ 1 borrow (clear cy) if TOS was 0
313 SUBC TOS,TOS \ 1 TOS=-1 if borrow was set
318 [UNDEFINED] U< [IF] \ define U< and U>
320 \ https://forth-standard.org/standard/core/Umore
324 U< ?GOTO FW1 \ 2 flag = true, Z = 0
325 BW1 AND #0,TOS \ 1 Z = 1
329 \ https://forth-standard.org/standard/core/Uless
330 \ U< u1 u2 -- flag test u1<u2, unsigned
332 SUB @PSP+,TOS \ 2 u2-u1
340 [UNDEFINED] < [IF] \ define < and >
342 \ https://forth-standard.org/standard/core/more
343 \ > n1 n2 -- flag test n1>n2, signed
345 SUB @PSP+,TOS \ 2 TOS=n2-n1
346 S< ?GOTO FW1 \ 2 --> +5
347 BW1 AND #0,TOS \ 1 flag Z = 1
351 \ https://forth-standard.org/standard/core/less
352 \ < n1 n2 -- flag test n1<n2, signed
354 SUB @PSP+,TOS \ 1 TOS=n2-n1
356 S< ?GOTO BW1 \ 2 signed
357 FW1 MOV #-1,TOS \ 1 flag Z = 0
362 \ ------------------------------------------------------------------------------
364 \ ------------------------------------------------------------------------------
365 \ THEN and BEGIN compile nothing
366 \ DO compile one word
367 \ IF, ELSE, AGAIN, UNTIL, WHILE, REPEAT, LOOP & +LOOP compile two words
368 \ LEAVE compile three words
370 [UNDEFINED] IF [IF] \ define IF THEN
372 \ https://forth-standard.org/standard/core/IF
373 \ IF -- IFadr initialize conditional forward branch
377 MOV &DP,TOS \ -- HERE
378 ADD #4,&DP \ compile one word, reserve one word
379 MOV #QFBRAN,0(TOS) \ -- HERE compile QFBRAN
380 ADD #2,TOS \ -- HERE+2=IFadr
384 \ https://forth-standard.org/standard/core/THEN
385 \ THEN IFadr -- resolve forward branch
387 MOV &DP,0(TOS) \ -- IFadr
393 [UNDEFINED] ELSE [IF]
394 \ https://forth-standard.org/standard/core/ELSE
395 \ ELSE IFadr -- ELSEadr resolve forward IF branch, leave ELSEadr on stack
397 ADD #4,&DP \ make room to compile two words
400 MOV W,0(TOS) \ HERE+4 ==> [IFadr]
402 MOV W,TOS \ -- ELSEadr
407 [UNDEFINED] BEGIN [IF] \ define BEGIN UNTIL AGAIN WHILE REPEAT
409 \ https://forth-standard.org/standard/core/BEGIN
410 \ BEGIN -- BEGINadr initialize backward branch
412 MOV #BEGIN,PC \ execute ASM BEGIN !
415 \ https://forth-standard.org/standard/core/UNTIL
416 \ UNTIL BEGINadr -- resolve conditional backward branch
419 BW1 ADD #4,&DP \ compile two words
421 MOV X,-4(W) \ compile Bran or QFBRAN at HERE
422 MOV TOS,-2(W) \ compile bakcward adr at HERE+2
427 \ https://forth-standard.org/standard/core/AGAIN
428 \ AGAIN BEGINadr -- resolve uncondionnal backward branch
434 \ https://forth-standard.org/standard/core/WHILE
435 \ WHILE BEGINadr -- WHILEadr BEGINadr
440 \ https://forth-standard.org/standard/core/REPEAT
441 \ REPEAT WHILEadr BEGINadr -- resolve WHILE loop
443 POSTPONE AGAIN POSTPONE THEN
447 [UNDEFINED] DO [IF] \ define DO LOOP +LOOP
449 HDNCODE XDO \ DO run time
450 MOV #$8000,X \ 2 compute 8000h-limit = "fudge factor"
452 MOV TOS,Y \ 1 loop ctr = index+fudge
453 ADD X,Y \ 1 Y = INDEX
454 PUSHM #2,X \ 4 PUSHM X,Y, i.e. PUSHM LIMIT, INDEX
459 \ https://forth-standard.org/standard/core/DO
460 \ DO -- DOadr L: -- 0
464 ADD #2,&DP \ make room to compile xdo
465 MOV &DP,TOS \ -- HERE+2
466 MOV #XDO,-2(TOS) \ compile xdo
467 ADD #2,&LEAVEPTR \ -- HERE+2 LEAVEPTR+2
469 MOV #0,0(W) \ -- HERE+2 L-- 0, init
473 HDNCODE XLOOP \ LOOP run time
474 ADD #1,0(RSP) \ 4 increment INDEX
475 BW1 BIT #$100,SR \ 2 is overflow bit set?
476 0= IF \ branch if no overflow
480 ADD #4,RSP \ 1 empties RSP
481 ADD #2,IP \ 1 overflow = loop done, skip branch ofs
482 MOV @IP+,PC \ 4 14~ taken or not taken xloop/loop
485 \ https://forth-standard.org/standard/core/LOOP
486 \ LOOP DOadr -- L-- an an-1 .. a1 0
489 BW2 ADD #4,&DP \ make room to compile two words
491 MOV X,-4(W) \ xloop --> HERE
492 MOV TOS,-2(W) \ DOadr --> HERE+2
493 BEGIN \ resolve all "leave" adr
494 MOV &LEAVEPTR,TOS \ -- Adr of top LeaveStack cell
495 SUB #2,&LEAVEPTR \ --
496 MOV @TOS,TOS \ -- first LeaveStack value
497 CMP #0,TOS \ -- = value left by DO ?
499 MOV W,0(TOS) \ move adr after loop as UNLOOP adr
505 \ https://forth-standard.org/standard/core/PlusLOOP
506 \ +LOOP adrs -- L-- an an-1 .. a1 0
507 HDNCODE XPLOO \ +LOOP run time
508 ADD TOS,0(RSP) \ 4 increment INDEX by TOS value
509 MOV @PSP+,TOS \ 2 get new TOS, doesn't change flags
520 \ https://forth-standard.org/standard/core/I
521 \ I -- n R: sys1 sys2 -- sys1 sys2
522 \ get the innermost loop index
524 SUB #2,PSP \ 1 make room in TOS
526 MOV @RSP,TOS \ 2 index = loopctr - fudge
533 \ https://forth-standard.org/standard/core/J
534 \ J -- n R: 4*sys -- 4*sys
535 \ C get the second loop index
545 [UNDEFINED] UNLOOP [IF]
546 \ https://forth-standard.org/standard/core/UNLOOP
547 \ UNLOOP -- R: sys1 sys2 -- drop loop parms
554 [UNDEFINED] LEAVE [IF]
555 \ https://forth-standard.org/standard/core/LEAVE
556 \ LEAVE -- L: -- adrs
558 MOV &DP,W \ compile three words
559 MOV #UNLOOP,0(W) \ [HERE] = UNLOOP
560 MOV #BRAN,2(W) \ [HERE+2] = BRAN
561 ADD #6,&DP \ [HERE+4] = at adr After LOOP
565 MOV W,0(X) \ leave HERE+4 on LEAVEPTR stack
571 \ https://forth-standard.org/standard/core/AND
572 \ C AND x1 x2 -- x3 logical AND
580 \ https://forth-standard.org/standard/core/OR
581 \ C OR x1 x2 -- x3 logical OR (BIS, BIts Set)
584 AND #-1,TOS \ to set flags
591 \ https://forth-standard.org/standard/core/XOR
592 \ C XOR x1 x2 -- x3 logical XOR
600 \ https://forth-standard.org/standard/core/OnePlus
601 \ 1+ n1/u1 -- n2/u2 add 1 to TOS
609 \ https://forth-standard.org/standard/core/OneMinus
610 \ 1- n1/u1 -- n2/u2 subtract 1 from TOS
617 [UNDEFINED] INVERT [IF]
618 \ https://forth-standard.org/standard/core/INVERT
619 \ INVERT x1 -- x2 bitwise inversion
626 [UNDEFINED] NEGATE [IF]
627 \ https://forth-standard.org/standard/core/NEGATE
628 \ C NEGATE x1 -- x2 two's complement
637 \ https://forth-standard.org/standard/core/ABS
638 \ C ABS n1 -- +n2 absolute value
648 [UNDEFINED] LSHIFT [IF]
649 \ https://forth-standard.org/standard/core/LSHIFT
650 \ LSHIFT x1 u -- x2 logical L shift u places
653 AND #$1F,TOS \ no need to shift more than 16
665 [UNDEFINED] RSHIFT [IF]
666 \ https://forth-standard.org/standard/core/RSHIFT
667 \ RSHIFT x1 u -- x2 logical R7 shift u places
670 AND #$1F,TOS \ no need to shift more than 16
673 BIC #C,SR \ Clr Carry
683 [UNDEFINED] MAX [IF] \ define MIN MAX
684 \ https://forth-standard.org/standard/core/MAX
685 \ MAX n1 n2 -- n3 signed maximum
693 \ https://forth-standard.org/standard/core/MIN
694 \ MIN n1 n2 -- n3 signed minimum
704 \ https://forth-standard.org/standard/core/TwoTimes
705 \ 2* x1 -- x2 arithmetic left shift
713 \ https://forth-standard.org/standard/core/TwoDiv
714 \ 2/ x1 -- x2 arithmetic right shift
721 \ --------------------
722 \ ARITHMETIC OPERATORS
723 \ --------------------
726 CODE TSTBIT \ addr bit_mask -- true/flase flag
732 \ $81EF DEVICEID @ U<
733 \ DEVICEID @ $81F3 U<
734 \ = [IF] ; MSP430FR413x subfamily without hardware_MPY
735 KERNEL_ADDON HMPY TSTBIT \ KERNEL_ADDON(BIT0) = hardware MPY flag
739 [IF] ; MSP430FRxxxx subfamily with hardware_MPY
742 \ https://forth-standard.org/standard/core/MTimes
743 \ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
745 MOV @PSP,&MPY \ Load 1st operand for unsigned multiplication
746 BW1 MOV TOS,&OP2 \ Load 2nd operand
747 MOV &RES0,0(PSP) \ low result on stack
748 MOV &RES1,TOS \ high result in TOS
752 \ https://forth-standard.org/standard/core/MTimes
753 \ M* n1 n2 -- dlo dhi signed 16*16->32 multiply
755 MOV @PSP,&MPYS \ Load 1st operand for signed multiplication
760 [ELSE] ; MSP430FR413x without hardware_MPY
763 \ T.I. UNSIGNED MULTIPLY SUBROUTINE: U1 x U2 -> Ud
764 \ https://forth-standard.org/standard/core/UMTimes
765 \ UM* u1 u2 -- ud unsigned 16x16->32 mult.
771 MOV #1,W \1 BIT TEST REGISTER
773 BIT W,TOS \1 TEST ACTUAL BIT ud2lo
775 ADD S,X \1 ADD ud1lo TO RESlo
776 ADDC T,Y \1 ADDC ud1hi TO REShi
778 ADD S,S \1 (RLA LSBs) ud1lo x 2
779 ADDC T,T \1 (RLC MSBs) ud1hi x 2
780 ADD W,W \1 (RLA) NEXT BIT TO TEST
781 U>= UNTIL \2 IF BIT IN CARRY: FINISHED 10~ loop
782 MOV X,0(PSP) \3 low result on stack
783 MOV Y,TOS \1 high result in TOS
784 MOV @IP+,PC \4 17 words
789 \ https://forth-standard.org/standard/core/UMTimes
790 \ UM* u1 u2 -- udlo udhi unsigned 16x16->32 mult.
795 XOR #-1,0(PSP) \ n1 --> u1
798 XOR TOS,S \ S contains sign of result
799 CMP #0,TOS \ n2 > -1 ?
801 XOR #-1,TOS \ n2 --> u2
804 PUSHM #2,IP \ UMSTAR use S,T,W,X,Y
808 POPM #2,IP \ pop S,IP
809 CMP #0,S \ sign of result > -1 ?
811 XOR #-1,0(PSP) \ ud --> d
819 [THEN] ; endof hardware_MPY
823 \ https://forth-standard.org/standard/core/UMDivMOD
824 \ UM/MOD udlo|udhi u1 -- r q unsigned 32/16->r16 q16
827 MOV #MUSMOD,PC \ execute MUSMOD then return to DROP
831 KERNEL_ADDON @ 0< ; test the switch: FLOORED/SYMETRIC DIVISION
833 [UNDEFINED] FM/MOD [IF]
834 \ https://forth-standard.org/standard/core/FMDivMOD
835 \ FM/MOD d1 n1 -- r q floored signed div'n
839 CMP #0,TOS \ n2 >= 0 ?
842 ADD #1,TOS \ -- d1 u2
844 CMP #0,0(PSP) \ d1hi >= 0 ?
846 XOR #-1,2(PSP) \ d1lo
847 XOR #-1,0(PSP) \ d1hi
848 ADD #1,2(PSP) \ d1lo+1
849 ADDC #0,0(PSP) \ d1hi+C
850 THEN \ -- uDVDlo uDVDhi uDIVlo
851 PUSHM #2,S \ 4 PUSHM S,T
854 POPM #2,S \ 4 POPM T,S
855 CMP #0,T \ T=DVDhi --> REM_sign
860 XOR S,T \ S=DIV XOR T=DVDhi = Quot_sign
861 CMP #0,T \ -- n3 u4 T=quot_sign
865 THEN \ -- n3 n4 S=divisor
867 CMP #0,0(PSP) \ remainder <> 0 ?
869 CMP #1,TOS \ quotient < 1 ?
871 ADD S,0(PSP) \ add divisor to remainder
872 SUB #1,TOS \ decrement quotient
879 [UNDEFINED] SM/REM [IF]
880 \ https://forth-standard.org/standard/core/SMDivREM
881 \ SM/REM DVDlo DVDhi DIV -- r3 q4 symmetric signed div
885 CMP #0,TOS \ n2 >= 0 ?
888 ADD #1,TOS \ -- d1 u2
890 CMP #0,0(PSP) \ d1hi >= 0 ?
892 XOR #-1,2(PSP) \ d1lo
893 XOR #-1,0(PSP) \ d1hi
894 ADD #1,2(PSP) \ d1lo+1
895 ADDC #0,0(PSP) \ d1hi+C
896 THEN \ -- uDVDlo uDVDhi uDIVlo
897 PUSHM #2,S \ 4 PUSHM S,T
900 POPM #2,S \ 4 POPM T,S
901 CMP #0,T \ T=DVDhi --> REM_sign
906 XOR S,T \ S=DIV XOR T=DVDhi = Quot_sign
907 CMP #0,T \ -- n3 u4 T=quot_sign
911 THEN \ -- n3 n4 S=divisor
918 \ https://forth-standard.org/standard/core/Times
919 \ * n1 n2 -- n3 signed multiply
925 [UNDEFINED] /MOD [IF]
926 \ https://forth-standard.org/standard/core/DivMOD
927 \ /MOD n1 n2 -- r3 q4 signed division
930 [ KERNEL_ADDON @ 0< ] \ test the switch: FLOORED / SYMETRIC DIVISION
938 \ https://forth-standard.org/standard/core/Div
939 \ / n1 n2 -- n3 signed quotient
942 [ KERNEL_ADDON @ 0< ] \ test the switch: FLOORED / SYMETRIC DIVISION
951 \ https://forth-standard.org/standard/core/MOD
952 \ MOD n1 n2 -- n3 signed remainder
955 [ KERNEL_ADDON @ 0< ] \ test the switch: FLOORED / SYMETRIC DIVISION
963 [UNDEFINED] */MOD [IF]
964 \ https://forth-standard.org/standard/core/TimesDivMOD
965 \ */MOD n1 n2 n3 -- r4 q5 signed mult/div
968 [ KERNEL_ADDON @ 0< ] \ test the switch: FLOORED / SYMETRIC DIVISION
976 \ https://forth-standard.org/standard/core/TimesDiv
977 \ */ n1 n2 n3 -- n4 n1*n2/q3
980 [ KERNEL_ADDON @ 0< ] \ test the switch: FLOORED / SYMETRIC DIVISION
988 \ -------------------------------------------------------------------------------
990 \ -------------------------------------------------------------------------------
992 \ https://forth-standard.org/standard/core/ROT
993 \ ROT x1 x2 x3 -- x2 x3 x1
995 MOV @PSP,W \ 2 fetch x2
996 MOV TOS,0(PSP) \ 3 store x3
997 MOV 2(PSP),TOS \ 3 fetch x1
998 MOV W,2(PSP) \ 3 store x2
1004 \ https://forth-standard.org/standard/core/RFetch
1005 \ R@ -- x R: x -- x fetch from return stack
1014 [UNDEFINED] TUCK [IF]
1015 \ https://forth-standard.org/standard/core/TUCK
1016 \ TUCK ( x1 x2 -- x2 x1 x2 )
1020 \ ----------------------------------------------------------------------
1022 \ ----------------------------------------------------------------------
1024 \ https://forth-standard.org/standard/core/TwoFetch
1025 \ 2@ a-addr -- x1 x2 fetch 2 cells ; the lower address will appear on top of stack
1035 \ https://forth-standard.org/standard/core/TwoStore
1036 \ 2! x1 x2 a-addr -- store 2 cells ; the top of stack is stored at the lower adr
1045 [UNDEFINED] 2DUP [IF]
1046 \ https://forth-standard.org/standard/core/TwoDUP
1047 \ 2DUP x1 x2 -- x1 x2 x1 x2 dup top 2 cells
1049 MOV @PSP,-4(PSP) \ 4
1056 [UNDEFINED] 2DROP [IF]
1057 \ https://forth-standard.org/standard/core/TwoDROP
1058 \ 2DROP x1 x2 -- drop 2 cells
1066 [UNDEFINED] 2SWAP [IF]
1067 \ https://forth-standard.org/standard/core/TwoSWAP
1068 \ 2SWAP x1 x2 x3 x4 -- x3 x4 x1 x2
1070 MOV @PSP,W \ -- x1 x2 x3 x4 W=x3
1071 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x4
1072 MOV W,4(PSP) \ -- x3 x2 x1 x4
1073 MOV TOS,W \ -- x3 x2 x1 x4 W=x4
1074 MOV 2(PSP),TOS \ -- x3 x2 x1 x2 W=x4
1075 MOV W,2(PSP) \ -- x3 x4 x1 x2
1080 [UNDEFINED] 2OVER [IF]
1081 \ https://forth-standard.org/standard/core/TwoOVER
1082 \ 2OVER x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2
1084 SUB #4,PSP \ -- x1 x2 x3 x x x4
1085 MOV TOS,2(PSP) \ -- x1 x2 x3 x4 x x4
1086 MOV 8(PSP),0(PSP) \ -- x1 x2 x3 x4 x1 x4
1087 MOV 6(PSP),TOS \ -- x1 x2 x3 x4 x1 x2
1092 \ ----------------------------------------------------------------------
1093 \ ALIGNMENT OPERATORS
1094 \ ----------------------------------------------------------------------
1095 [UNDEFINED] ALIGNED [IF]
1096 \ https://forth-standard.org/standard/core/ALIGNED
1097 \ ALIGNED addr -- a-addr align given addr
1105 [UNDEFINED] ALIGN [IF]
1106 \ https://forth-standard.org/standard/core/ALIGN
1107 \ ALIGN -- align HERE
1115 \ ---------------------
1116 \ PORTABILITY OPERATORS
1117 \ ---------------------
1118 [UNDEFINED] CHARS [IF]
1119 \ https://forth-standard.org/standard/core/CHARS
1120 \ CHARS n1 -- n2 chars->adrs units
1126 [UNDEFINED] CHAR+ [IF]
1127 \ https://forth-standard.org/standard/core/CHARPlus
1128 \ CHAR+ c-addr1 -- c-addr2 add char size
1135 [UNDEFINED] CELLS [IF]
1136 \ https://forth-standard.org/standard/core/CELLS
1137 \ CELLS n1 -- n2 cells->adrs units
1144 [UNDEFINED] CELL+ [IF]
1145 \ https://forth-standard.org/standard/core/CELLPlus
1146 \ CELL+ a-addr1 -- a-addr2 add cell size
1153 \ ---------------------------
1154 \ BLOCK AND STRING COMPLEMENT
1155 \ ---------------------------
1157 [UNDEFINED] CHAR [IF]
1158 \ https://forth-standard.org/standard/core/CHAR
1159 \ CHAR -- char parse ASCII character
1165 [UNDEFINED] [CHAR] [IF]
1166 \ https://forth-standard.org/standard/core/BracketCHAR
1167 \ [CHAR] -- compile character literal
1169 CHAR POSTPONE LITERAL
1174 \ https://forth-standard.org/standard/core/PlusStore
1175 \ +! n/u a-addr -- add n/u to memory
1183 [UNDEFINED] MOVE [IF]
1184 \ https://forth-standard.org/standard/core/MOVE
1185 \ MOVE addr1 addr2 u -- smart move
1186 \ VERSION FOR 1 ADDRESS UNIT = 1 CHAR
1189 MOV @PSP+,Y \ Y = addr2 = dst
1190 MOV @PSP+,X \ X = addr1 = src
1191 MOV @PSP+,TOS \ pop new TOS
1192 CMP #0,W \ count = 0 ?
1193 0<> IF \ if 0, already done !
1194 CMP X,Y \ dst = src ?
1195 0<> IF \ if 0, already done !
1196 U< IF \ U< if src > dst
1197 BEGIN \ copy W bytes
1202 MOV @IP+,PC \ out 1 of MOVE ====>
1203 THEN \ U>= if dst > src
1204 ADD W,Y \ copy W bytes beginning with the end
1214 MOV @IP+,PC \ out 2 of MOVE ====>
1218 [UNDEFINED] FILL [IF]
1219 \ https://forth-standard.org/standard/core/FILL
1220 \ FILL c-addr u char -- fill memory with char
1223 MOV @PSP+,W \ address
1227 MOV.B TOS,0(W) \ store char in memory
1232 MOV @PSP+,TOS \ empties stack
1237 \ --------------------
1238 \ INTERPRET COMPLEMENT
1239 \ --------------------
1240 [UNDEFINED] HEX [IF]
1241 \ https://forth-standard.org/standard/core/HEX
1248 [UNDEFINED] DECIMAL [IF]
1249 \ https://forth-standard.org/standard/core/DECIMAL
1257 \ https://forth-standard.org/standard/core/p
1258 \ ( -- skip input until char ) or EOL
1264 [UNDEFINED] .( [IF] ; "
1265 \ https://forth-standard.org/standard/core/Dotp
1266 \ .( -- type comment immediatly.
1271 [ ' WORD 16 + , ] \ for volatile CAPS OFF
1279 [UNDEFINED] >BODY [IF]
1280 \ https://forth-standard.org/standard/core/toBODY
1281 \ >BODY -- addr leave BODY of a CREATEd word\ also leave default ACTION-OF primary DEFERred word
1288 [UNDEFINED] EXECUTE [IF]
1289 \ https://forth-standard.org/standard/core/EXECUTE
1290 \ EXECUTE i*x xt -- j*x execute Forth word at 'xt'
1296 [UNDEFINED] EVALUATE [IF]
1297 \ EVALUATE upside down...
1298 CODENNM \ as the end of EVALUATE
1300 MOV @RSP+,&SOURCE_ORG \ 4
1301 MOV @RSP+,&SOURCE_LEN \ 4
1304 ENDCODE \ -- end_of_EVALUATE_addr
1306 \ https://forth-standard.org/standard/core/EVALUATE
1307 \ EVALUATE \ i*x c-addr u -- j*x interpret string
1309 MOV #SOURCE_LEN,X \ 2
1310 MOV @X+,S \ 2 S = SOURCE_LEN
1311 MOV @X+,T \ 2 T = SOURCE_ORG
1312 MOV @X+,W \ 2 W = TOIN
1313 PUSHM #4,IP \ 6 PUSHM IP,S,T,W
1315 ADD #8,IP \ 1 IP = ENDCODE PC address
1316 MOV #INTERPRET,PC \ 3 addr defined in MSP430FRxxxx.pat
1317 NOP \ 0 stuffing instruction (never executed)
1319 , \ end_of_EVALUATE_addr -- compile the end_of_EVALUATE_addr
1323 [UNDEFINED] RECURSE [IF]
1324 \ https://forth-standard.org/standard/core/RECURSE
1325 \ C RECURSE -- recurse to current definition
1334 [UNDEFINED] SOURCE [IF]
1335 \ https://forth-standard.org/standard/core/SOURCE
1336 \ SOURCE -- adr u of current input buffer
1341 MOV &SOURCE_ORG,0(PSP)
1346 [UNDEFINED] VARIABLE [IF]
1347 \ https://forth-standard.org/standard/core/VARIABLE
1348 \ VARIABLE <name> -- define a Forth VARIABLE
1352 MOV #DOVAR,-4(W) \ CFA = CALL rDOVAR
1358 [UNDEFINED] CONSTANT [IF]
1359 \ https://forth-standard.org/standard/core/CONSTANT
1360 \ CONSTANT <name> n -- define a Forth CONSTANT
1364 MOV TOS,-2(W) \ PFA = n
1371 [UNDEFINED] STATE [IF]
1372 \ https://forth-standard.org/standard/core/STATE
1373 \ STATE -- a-addr holds compiler state
1374 STATEADR CONSTANT STATE
1377 [UNDEFINED] BASE [IF]
1378 \ https://forth-standard.org/standard/core/BASE
1379 \ BASE -- a-addr holds conversion radix
1380 BASEADR CONSTANT BASE
1383 [UNDEFINED] >IN [IF]
1384 \ https://forth-standard.org/standard/core/toIN
1385 \ C >IN -- a-addr holds offset in input stream
1389 [UNDEFINED] PAD [IF]
1390 \ https://forth-standard.org/standard/core/PAD
1392 PAD_ORG CONSTANT PAD
1396 \ https://forth-standard.org/standard/core/BL
1397 \ BL -- char an ASCII space
1401 [UNDEFINED] SPACE [IF]
1402 \ https://forth-standard.org/standard/core/SPACE
1403 \ SPACE -- output a space
1408 [UNDEFINED] SPACES [IF]
1409 \ https://forth-standard.org/standard/core/SPACES
1410 \ SPACES n -- output n spaces
1421 [UNDEFINED] DEFER [IF]
1422 \ https://forth-standard.org/standard/core/DEFER
1423 \ Skip leading space delimiters. Parse name delimited by a space.
1424 \ Create a definition for name with the execution semantics defined below.
1426 \ name Execution: --
1427 \ Execute the xt that name is set to execute, i.e. NEXT (nothing),
1428 \ until the phrase ' word IS name is executed, causing a new value of xt to be assigned to name.
1429 : DEFER \ useless definition for FAST FORTH...
1432 MOV #$4030,-4(W) \4 first CELL = MOV @PC+,PC = BR #addr
1433 MOV #NEXT_ADR,-2(W) \3 second CELL = ...mNEXT : do nothing by default
1440 \ https://forth-standard.org/standard/core/CR
1441 \ CR -- send CR+LF to the output device
1445 \ 'CR' EMIT 'LF' EMIT
1449 MOV #NEXT_ADR,PC \ compile same as DEFER
1458 \ https://forth-standard.org/standard/core/TO
1459 \ TO name Run-time: ( x -- )
1460 \ Assign the value x to named VALUE.
1467 [UNDEFINED] VALUE [IF]
1468 \ https://forth-standard.org/standard/core/VALUE
1469 \ ( x "<spaces>name" -- ) define a Forth VALUE
1470 \ Skip leading space delimiters. Parse name delimited by a space.
1471 \ Create a definition for name with the execution semantics defined below,
1472 \ with an initial value equal to x.
1474 \ name Execution: ( -- x )
1475 \ Place x on the stack. The value of x is that given when name was created,
1476 \ until the phrase x TO name is executed, causing a new value of x to be assigned to name.
1477 : VALUE \ x "<spaces>name" --
1482 BIT #UF9,SR \ 2 see TO
1483 0= IF \ 2 if UF9 is not set
1484 MOV #@,PC \ execute FETCH
1486 BIC #UF9,SR \ 2 clear UF9 flag
1487 MOV #!,PC \ execute STORE
1491 [UNDEFINED] CASE [IF] \ define CASE OF ENDOF ENDCASE
1493 \ https://forth-standard.org/standard/core/CASE
1496 ; IMMEDIATE \ -- #of-1
1498 \ https://forth-standard.org/standard/core/OF
1499 : OF \ #of-1 -- orgOF #of
1501 >R \ move off the stack in case the control-flow stack is the data stack.
1502 POSTPONE OVER POSTPONE = \ copy and test case value
1503 POSTPONE IF \ add orig to control flow stack
1504 POSTPONE DROP \ discards case value if =
1505 R> \ we can bring count back now
1508 \ https://forth-standard.org/standard/core/ENDOF
1509 : ENDOF \ orgOF #of -- orgENDOF #of
1510 >R \ move off the stack in case the control-flow stack is the data stack.
1512 R> \ we can bring count back now
1515 \ https://forth-standard.org/standard/core/ENDCASE
1516 : ENDCASE \ orgENDOF1..orgENDOFn #of --
1529 ; CORE_ANS.f is loaded