1 \ -*- coding: utf-8 -*-
3 \ to see kernel options, download FastForthSpecs.f
4 \ FastForth kernel options: MSP430ASSEMBLER, CONDCOMP, DOUBLE_INPUT
6 \ TARGET SELECTION ( = the name of \INC\target.pat file without the extension)
7 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
8 \ MSP_EXP430FR4133 MSP_EXP430FR2433 CHIPSTICK_FR2433 MSP_EXP430FR2355
11 \ from scite editor : copy your target selection in (shift+F8) parameter 1:
15 \ drag and drop this file onto SendSourceFileToTarget.bat
16 \ then select your TARGET when asked.
20 \ rDODOES to rEXIT must be saved before use and restored after
21 \ scratch registers Y to S are free for use
22 \ under interrupt, IP is free for use
24 \ FORTH conditionnals: unary{ 0= 0< 0> }, binary{ = < > U< }
26 \ ASSEMBLER conditionnal usage with IF UNTIL WHILE S< S>= U< U>= 0= 0<> 0>=
28 \ ASSEMBLER conditionnal usage with ?GOTO S< S>= U< U>= 0= 0<> 0<
36 0<> IF MOV #0,TOS THEN \ if TOS <> 0 (DOUBLE input), set TOS = 0
39 SUB #308,TOS \ FastForth V3.8
41 $0D EMIT \ return to column 1 without CR
42 ABORT" FastForth V3.8 please!"
43 ABORT" build FastForth with DOUBLE_INPUT addon !"
44 PWR_STATE \ if no abort remove this word
49 ; -----------------------------------------------------
51 ; -----------------------------------------------------
53 [DEFINED] {DOUBLE} [IF] {DOUBLE} [THEN]
58 \ https://forth-standard.org/standard/core/toR
59 \ >R x -- R: -- x push to return stack
68 \ https://forth-standard.org/standard/core/Rfrom
69 \ R> -- x R: x -- pop from return stack ; CALL #RFROM performs DOVAR
79 \ https://forth-standard.org/standard/core/Fetch
80 \ @ c-addr -- char fetch char from memory
88 \ https://forth-standard.org/standard/core/Store
89 \ ! x a-addr -- store cell in memory
98 \ https://forth-standard.org/standard/core/CFetch
99 \ C@ c-addr -- char fetch char from memory
106 [UNDEFINED] SWAP [IF]
107 \ https://forth-standard.org/standard/core/SWAP
108 \ SWAP x1 x2 -- x2 x1 swap top two items
117 [UNDEFINED] OVER [IF]
118 \ https://forth-standard.org/standard/core/OVER
119 \ OVER x1 x2 -- x1 x2 x1
121 MOV TOS,-2(PSP) \ 3 -- x1 (x2) x2
122 MOV @PSP,TOS \ 2 -- x1 (x2) x1
123 SUB #2,PSP \ 1 -- x1 x2 x1
129 \ https://forth-standard.org/standard/core/ROT
130 \ ROT x1 x2 x3 -- x2 x3 x1
132 MOV @PSP,W \ 2 fetch x2
133 MOV TOS,0(PSP) \ 3 store x3
134 MOV 2(PSP),TOS \ 3 fetch x1
135 MOV W,2(PSP) \ 3 store x2
141 \ https://forth-standard.org/standard/core/Minus
142 \ - n1/u1 n2/u2 -- n3/u3 n3 = n1-n2
144 SUB @PSP+,TOS \ 2 -- n2-n1 ( = -n3)
146 ADD #1,TOS \ 1 -- n3 = -(n2-n1) = n1-n2
151 [UNDEFINED] < [IF] \ define < and >
152 \ https://forth-standard.org/standard/core/less
153 \ < n1 n2 -- flag test n1<n2, signed
155 SUB @PSP+,TOS \ 1 TOS=n2-n1
156 S< ?GOTO FW1 \ 2 signed
158 BW1 MOV #-1,TOS \ 1 flag Z = 0
163 \ https://forth-standard.org/standard/core/more
164 \ > n1 n2 -- flag test n1>n2, signed
166 SUB @PSP+,TOS \ 2 TOS=n2-n1
167 S< ?GOTO BW1 \ 2 --> +5
168 FW1 AND #0,TOS \ 1 flag Z = 1
173 [UNDEFINED] IF [IF] \ define IF THEN
174 \ https://forth-standard.org/standard/core/IF
175 \ IF -- IFadr initialize conditional forward branch
179 MOV &DP,TOS \ -- HERE
180 ADD #4,&DP \ compile one word, reserve one word
181 MOV #QFBRAN,0(TOS) \ -- HERE compile QFBRAN
182 ADD #2,TOS \ -- HERE+2=IFadr
186 \ https://forth-standard.org/standard/core/THEN
187 \ THEN IFadr -- resolve forward branch
188 CODE THEN \ immediate
189 MOV &DP,0(TOS) \ -- IFadr
195 [UNDEFINED] ELSE [IF]
196 \ https://forth-standard.org/standard/core/ELSE
197 \ ELSE IFadr -- ELSEadr resolve forward IF branch, leave ELSEadr on stack
198 CODE ELSE \ immediate
199 ADD #4,&DP \ make room to compile two words
202 MOV W,0(TOS) \ HERE+4 ==> [IFadr]
204 MOV W,TOS \ -- ELSEadr
210 \ https://forth-standard.org/standard/core/TO
217 [UNDEFINED] DOES> [IF]
218 \ https://forth-standard.org/standard/core/DOES
219 \ DOES> -- set action for the latest CREATEd definition
221 MOV &LAST_CFA,W \ W = CFA of CREATEd word
222 MOV #DODOES,0(W) \ replace CFA (DOCON) by new CFA (DODOES)
223 MOV IP,2(W) \ replace PFA by the address after DOES> as execution address
229 [UNDEFINED] SPACES [IF]
230 \ https://forth-standard.org/standard/core/SPACES
231 \ SPACES n -- output n spaces
245 MOV @PSP+,TOS \ -- drop n
251 \ https://forth-standard.org/standard/core/TwoFetch
252 \ 2@ a-addr -- x1 x2 fetch 2 cells ; the lower address will appear on top of stack
262 \ https://forth-standard.org/standard/core/TwoStore
263 \ 2! x1 x2 a-addr -- store 2 cells ; the top of stack is stored at the lower adr
272 [UNDEFINED] 2DUP [IF]
273 \ https://forth-standard.org/standard/core/TwoDUP
274 \ 2DUP x1 x2 -- x1 x2 x1 x2 dup top 2 cells
276 SUB #4,PSP \ -- x1 x x x2
277 MOV TOS,2(PSP) \ -- x1 x2 x x2
278 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x2
283 [UNDEFINED] 2DROP [IF]
284 \ https://forth-standard.org/standard/core/TwoDROP
285 \ 2DROP x1 x2 -- drop 2 cells
293 [UNDEFINED] 2SWAP [IF]
294 \ https://forth-standard.org/standard/core/TwoSWAP
295 \ 2SWAP x1 x2 x3 x4 -- x3 x4 x1 x2
297 MOV @PSP,W \ -- x1 x2 x3 x4 W=x3
298 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x4
299 MOV W,4(PSP) \ -- x3 x2 x1 x4
300 MOV TOS,W \ -- x3 x2 x1 x4 W=x4
301 MOV 2(PSP),TOS \ -- x3 x2 x1 x2 W=x4
302 MOV W,2(PSP) \ -- x3 x4 x1 x2
307 [UNDEFINED] 2OVER [IF]
308 \ https://forth-standard.org/standard/core/TwoOVER
309 \ 2OVER x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2
311 SUB #4,PSP \ -- x1 x2 x3 x x x4
312 MOV TOS,2(PSP) \ -- x1 x2 x3 x4 x x4
313 MOV 8(PSP),0(PSP) \ -- x1 x2 x3 x4 x1 x4
314 MOV 6(PSP),TOS \ -- x1 x2 x3 x4 x1 x2
320 \ https://forth-standard.org/standard/core/TwotoR
321 \ ( x1 x2 -- ) ( R: -- x1 x2 ) Transfer cell pair x1 x2 to the return stack.
331 \ https://forth-standard.org/standard/core/TwoRFetch
332 \ ( -- x1 x2 ) ( R: x1 x2 -- x1 x2 ) Copy cell pair x1 x2 from the return stack.
343 \ https://forth-standard.org/standard/core/TwoRfrom
344 \ ( -- x1 x2 ) ( R: x1 x2 -- ) Transfer cell pair x1 x2 from the return stack
354 \ ===============================================
356 \ ===============================================
359 \ https://forth-standard.org/standard/double/Dd
360 \ D. dlo dhi -- display d (signed)
362 MOV #U.,W \ U. + 10 = D.
368 [UNDEFINED] 2ROT [IF]
369 \ https://forth-standard.org/standard/double/TwoROT
370 \ Rotate the top three cell pairs on the stack bringing cell pair x1 x2 to the top of the stack.
374 MOV 4(PSP),8(PSP) \ 5
375 MOV 2(PSP),6(PSP) \ 5
385 \ https://forth-standard.org/standard/double/DtoS
386 \ D>S d -- n double prec -> single.
394 \ https://forth-standard.org/standard/double/DZeroEqual
410 \ https://forth-standard.org/standard/double/DZeroless
423 \ https://forth-standard.org/standard/double/DEqual
425 CMP TOS,2(PSP) \ 3 ud1H - ud2H
428 CMP @PSP,4(PSP) \ 4 ud1L - ud2L
439 \ https://forth-standard.org/standard/double/Dless
440 \ flag is true if and only if d1 is less than d2
442 CMP TOS,2(PSP) \ 3 d1H - d2H
448 CMP @PSP,4(PSP) \ 4 d1L - d2L
459 \ https://forth-standard.org/standard/double/DUless
460 \ flag is true if and only if ud1 is less than ud2
462 CMP TOS,2(PSP) \ 3 ud1H - ud2H
468 CMP @PSP,4(PSP) \ 4 ud1L - ud2L
479 \ https://forth-standard.org/standard/double/DPlus
488 \ https://forth-standard.org/standard/double/MPlus
502 \ https://forth-standard.org/standard/double/DMinus
511 [UNDEFINED] DNEGATE [IF]
512 \ https://forth-standard.org/standard/double/DNEGATE
522 [UNDEFINED] DABS [IF]
523 \ https://forth-standard.org/standard/double/DABS
524 \ DABS d1 -- |d1| absolute value
535 \ https://forth-standard.org/standard/double/DTwoDiv
544 \ https://forth-standard.org/standard/double/DTwoTimes
552 [UNDEFINED] DMAX [IF]
553 \ https://forth-standard.org/standard/double/DMAX
555 2OVER 2OVER \ -- d1 d2 d1 d2
557 2>R 2DROP 2R> \ -- d2
564 [UNDEFINED] DMIN [IF]
565 \ https://forth-standard.org/standard/double/DMIN
567 2OVER 2OVER \ -- d1 d2 d1 d2
570 ELSE 2>R 2DROP 2R> \ -- d1 d2
574 DEVICEID C@ $EF > [IF] ; test for MSP430FR413x devices without hardware_MPY
577 \ https://forth-standard.org/standard/double/MTimesDiv
578 CODE M*/ \ d1lo d1hi n1 +n2 -- d2lo d2hi
579 BIC #UF9,SR \ clear RES sign flag
580 CMP #0,2(PSP) \ d1 < 0 ?
586 BIS #UF9,SR \ set RES sign flag
588 CMP #0,0(PSP) \ n1 < 0 ?
593 THEN \ let's process UM* -- ud1lo ud1hi u1 +n2
594 MOV 4(PSP),Y \ 3 uMDlo
595 MOV 2(PSP),T \ 3 uMDhi
596 MOV @PSP+,S \ 2 uMRlo -- ud1lo ud1hi +n2
597 MOV #0,rDODOES \ 1 uMDlo=0
598 MOV #0,2(PSP) \ 3 uRESlo=0
599 MOV #0,0(PSP) \ 3 uRESmi=0 -- uRESlo uRESmi +n2
600 MOV #0,W \ 1 uREShi=0
601 MOV #1,X \ 1 BIT TEST REGlo
602 BEGIN BIT X,S \ 1 test actual bit in uMRlo
603 0<> IF ADD Y,2(PSP) \ 3 IF 1: ADD uMDlo TO uRESlo
604 ADDC T,0(PSP) \ 3 ADDC uMDmi TO uRESmi
605 ADDC rDODOES,W \ 1 ADDC uMRlo TO uREShi
606 THEN ADD Y,Y \ 1 (RLA LSBs) uMDlo *2
607 ADDC T,T \ 1 (RLC MSBs) uMDhi *2
608 ADDC rDODOES,rDODOES \ 1 (RLA LSBs) uMDlo *2
609 ADD X,X \ 1 (RLA) NEXT BIT TO TEST
610 U>= UNTIL \ 1 IF BIT IN CARRY: FINISHED W=uREShi
620 \ ----------------------------
625 \ X = Don't care QUOTlo
626 \ Y = Don't care QUOThi
631 MOV #32,rDODOES \ 2 init loop count
632 CMP #0,W \ DVDhi = 0 ?
634 MOV TOS,W \ DVDmi --> DVDhi
635 CALL #MDIV1DIV2 \ with loop count / 2
637 CALL #MDIV1 \ -- urem ud2lo ud2hi
639 MOV @PSP+,0(PSP) \ -- ud2lo ud2hi
640 BIT #UF9,SR \ sign is set ?
641 0<> IF \ DNEGATE Quot
646 BIC #UF9,SR \ clear sign flag
647 \ now, make floored division, only used if rem<>0 and quot<0 :
648 CMP #0,W \ remainder <> 0 ?
650 SUB #1,0(PSP) \ decrement quotient
658 [ELSE] \ hardware multiplier
661 \ https://forth-standard.org/standard/double/MTimesDiv
662 CODE M*/ \ d1 * n1 / +n2 -- d2
663 MOV 4(PSP),&MPYS32L \ 5 Load 1st operand d1lo
664 MOV 2(PSP),&MPYS32H \ 5 d1hi
665 MOV @PSP+,&OP2 \ 4 -- d1 n2 load 2nd operand n1
668 MOV &RES0,S \ 3 S = RESlo
669 MOV &RES1,TOS \ 3 TOS = RESmi
670 MOV &RES2,W \ 3 W = REShi
671 BIC #UF9,SR \ clear sign flag
672 CMP #0,W \ negative product ?
673 S< IF \ compute ABS value if yes
680 BIS #UF9,SR \ set sign flag
684 \ ----------------------------
689 \ X = Don't care QUOTlo
690 \ Y = Don't care QUOThi
695 MOV #32,rDODOES \ 2 init loop count
696 CMP #0,W \ DVDhi = 0 ?
698 MOV TOS,W \ DVDmi --> DVDhi
699 CALL #MDIV1DIV2 \ with loop count / 2
701 CALL #MDIV1 \ -- urem ud2lo ud2hi
703 MOV @PSP+,0(PSP) \ -- d2lo d2hi
704 BIT #UF9,SR \ RES sign is set ?
710 BIC #UF9,SR \ clear sign flag
711 \ now, make floored division, only used if rem<>0 and quot<0 :
712 CMP #0,W \ remainder <> 0 ?
714 SUB #1,0(PSP) \ decrement quotient
718 MOV @IP+,PC \ 52 words
722 [THEN] ; end of software/hardware_MPY
724 [UNDEFINED] 2VARIABLE [IF]
725 \ https://forth-standard.org/standard/double/TwoVARIABLE
735 [UNDEFINED] 2CONSTANT [IF]
736 \ https://forth-standard.org/standard/double/TwoCONSTANT
737 : 2CONSTANT \ udlo/dlo/Flo udhi/dhi/Shi -- to create double or s15q16 CONSTANT
739 , , \ compile Shi then Flo
745 [UNDEFINED] 2VALUE [IF]
746 \ https://forth-standard.org/standard/double/TwoVALUE
747 : 2VALUE \ x1 x2 "<spaces>name" --
748 CREATE , , \ compile Shi then Flo
752 BIT #UF9,SR \ flag set by TO
754 MOV #2@,PC \ execute TwoFetch
756 BIC #UF9,SR \ clear flag
757 MOV #2!,PC \ execute TwoStore
761 [UNDEFINED] 2LITERAL [IF]
762 \ https://forth-standard.org/standard/double/TwoLITERAL
764 BIS #UF9,SR \ see LITERAL
770 \ https://forth-standard.org/standard/double/DDotR
773 >R SWAP OVER DABS <# #S ROT SIGN #>
774 R> OVER - SPACES TYPE
780 \ ==============================================================================
781 \ Complement to pass DOUBLETEST.4TH
782 \ ==============================================================================
784 [UNDEFINED] VARIABLE [IF]
785 \ https://forth-standard.org/standard/core/VARIABLE
795 [UNDEFINED] CONSTANT [IF]
796 \ https://forth-standard.org/standard/core/CONSTANT
797 \ CONSTANT <name> n -- define a Forth CONSTANT
801 MOV TOS,-2(W) \ PFA = n
808 [UNDEFINED] CELLS [IF]
809 \ https://forth-standard.org/standard/core/CELLS
810 \ CELLS n1 -- n2 cells->adrs units
817 [UNDEFINED] ALLOT [IF]
818 \ https://forth-standard.org/standard/core/ALLOT
819 \ ALLOT n -- allocate n bytes
827 [UNDEFINED] DEPTH [IF]
828 \ https://forth-standard.org/standard/core/DEPTH
829 \ DEPTH -- +n number of items on stack, must leave 0 if stack empty
833 SUB PSP,TOS \ PSP-S0--> TOS
834 RRA TOS \ TOS/2 --> TOS
835 SUB #2,PSP \ post decrement stack...
841 \ https://forth-standard.org/standard/core/DUP
842 \ DUP x -- x x duplicate top of stack
844 BW1 SUB #2,PSP \ 2 push old TOS..
845 MOV TOS,0(PSP) \ 3 ..onto stack
849 \ https://forth-standard.org/standard/core/qDUP
850 \ ?DUP x -- 0 | x x DUP if nonzero
852 CMP #0,TOS \ 2 test for TOS nonzero
858 [UNDEFINED] DO [IF] \ define DO LOOP +LOOP
859 \ https://forth-standard.org/standard/core/DO
860 \ DO -- DOadr L: -- 0
864 ADD #2,&DP \ make room to compile xdo
865 MOV &DP,TOS \ -- HERE+2
866 MOV #XDO,-2(TOS) \ compile xdo
867 ADD #2,&LEAVEPTR \ -- HERE+2 LEAVEPTR+2
869 MOV #0,0(W) \ -- HERE+2 L-- 0
873 \ https://forth-standard.org/standard/core/LOOP
874 \ LOOP DOadr -- L-- an an-1 .. a1 0
875 CODE LOOP \ immediate
877 BW1 ADD #4,&DP \ make room to compile two words
879 MOV X,-4(W) \ xloop --> HERE
880 MOV TOS,-2(W) \ DOadr --> HERE+2
881 BEGIN \ resolve all "leave" adr
882 MOV &LEAVEPTR,TOS \ -- Adr of top LeaveStack cell
883 SUB #2,&LEAVEPTR \ --
884 MOV @TOS,TOS \ -- first LeaveStack value
885 CMP #0,TOS \ -- = value left by DO ?
887 MOV W,0(TOS) \ move adr after loop as UNLOOP adr
893 \ https://forth-standard.org/standard/core/PlusLOOP
894 \ +LOOP adrs -- L-- an an-1 .. a1 0
895 CODE +LOOP \ immediate
902 \ https://forth-standard.org/standard/core/I
903 \ I -- n R: sys1 sys2 -- sys1 sys2
904 \ get the innermost loop index
906 SUB #2,PSP \ 1 make room in TOS
908 MOV @RSP,TOS \ 2 index = loopctr - fudge
915 \ https://forth-standard.org/standard/core/Plus
916 \ + n1/u1 n2/u2 -- n3/u3 add n1+n2
924 \ https://forth-standard.org/standard/core/Equal
925 \ = x1 x2 -- flag test x1=x2
932 XOR #-1,TOS \ 1 flag Z = 1
938 \ https://forth-standard.org/standard/core/ZeroEqual
939 \ 0= n/u -- flag return true if TOS=0
941 SUB #1,TOS \ borrow (clear cy) if TOS was 0
942 SUBC TOS,TOS \ TOS=-1 if borrow was set
947 [UNDEFINED] SOURCE [IF]
948 \ https://forth-standard.org/standard/core/SOURCE
949 \ SOURCE -- adr u of current input buffer
954 MOV &SOURCE_ORG,0(PSP)
960 \ https://forth-standard.org/standard/core/toIN
961 \ C >IN -- a-addr holds offset in input stream
965 [UNDEFINED] SWAP [IF]
966 \ https://forth-standard.org/standard/core/SWAP
967 \ SWAP x1 x2 -- x2 x1 swap top two items
976 [UNDEFINED] DROP [IF]
977 \ https://forth-standard.org/standard/core/DROP
978 \ DROP x -- drop top of stack
986 \ https://forth-standard.org/standard/core/OnePlus
987 \ 1+ n1/u1 -- n2/u2 add 1 to TOS
994 [UNDEFINED] CHAR [IF]
995 \ https://forth-standard.org/standard/core/CHAR
996 \ CHAR -- char parse ASCII character
1002 [UNDEFINED] [CHAR] [IF]
1003 \ https://forth-standard.org/standard/core/BracketCHAR
1004 \ [CHAR] -- compile character literal
1006 CHAR POSTPONE LITERAL
1011 \ https://forth-standard.org/standard/core/TwoDiv
1012 \ 2/ x1 -- x2 arithmetic right shift
1019 [UNDEFINED] INVERT [IF]
1020 \ https://forth-standard.org/standard/core/INVERT
1021 \ INVERT x1 -- x2 bitwise inversion
1028 [UNDEFINED] RSHIFT [IF]
1029 \ https://forth-standard.org/standard/core/RSHIFT
1030 \ RSHIFT x1 u -- x2 logical R7 shift u places
1033 AND #$1F,TOS \ no need to shift more than 16
1035 BEGIN BIC #C,SR \ Clr Carry
1045 \ https://forth-standard.org/standard/core/Zeroless
1046 \ 0< n -- flag true if TOS negative
1048 ADD TOS,TOS \ 1 set carry if TOS negative
1049 SUBC TOS,TOS \ 1 TOS=-1 if carry was clear
1050 XOR #-1,TOS \ 1 TOS=-1 if carry was set
1055 [UNDEFINED] S>D [IF]
1056 \ https://forth-standard.org/standard/core/StoD
1057 \ S>D n -- d single -> double prec.
1064 \ https://forth-standard.org/standard/core/OneMinus
1065 \ 1- n1/u1 -- n2/u2 subtract 1 from TOS
1072 [UNDEFINED] UM/MOD [IF]
1073 \ https://forth-standard.org/standard/core/UMDivMOD
1074 \ UM/MOD udlo|udhi u1 -- r q unsigned 32/16->r16 q16
1077 MOV #MUSMOD,PC \ execute MUSMOD then return to DROP
1081 [UNDEFINED] SM/REM [IF]
1082 \ https://forth-standard.org/standard/core/SMDivREM
1083 \ SM/REM DVDlo DVDhi DIVlo -- r3 q4 symmetric signed div
1086 MOV @PSP,T \ T=DVD_sign==>rem_sign
1087 CMP #0,TOS \ n2 >= 0 ?
1090 ADD #1,TOS \ -- d1 u2
1092 CMP #0,0(PSP) \ d1hi >= 0 ?
1094 XOR #-1,2(PSP) \ d1lo
1095 XOR #-1,0(PSP) \ d1hi
1096 ADD #1,2(PSP) \ d1lo+1
1097 ADDC #0,0(PSP) \ d1hi+C
1098 THEN \ -- uDVDlo uDVDhi uDIVlo
1099 PUSHM #3,IP \ save IP,S,T
1101 UM/MOD \ -- uREMlo uQUOTlo
1103 POPM #3,IP \ restore T,S,IP
1104 CMP #0,T \ T=rem_sign
1109 XOR S,T \ S=divisor T=quot_sign
1110 CMP #0,T \ -- n3 u4 T=quot_sign
1114 THEN \ -- n3 n4 S=divisor
1119 [UNDEFINED] FM/MOD [IF]
1120 \ https://forth-standard.org/standard/core/FMDivMOD
1121 \ FM/MOD d1 n1 -- r q floored signed div'n
1124 HI2LO \ -- remainder quotient S=divisor
1125 CMP #0,0(PSP) \ remainder <> 0 ?
1127 CMP #1,TOS \ quotient < 1 ?
1129 ADD S,0(PSP) \ add divisor to remainder
1130 SUB #1,TOS \ decrement quotient
1138 [UNDEFINED] NIP [IF]
1139 \ https://forth-standard.org/standard/core/NIP
1140 \ NIP x1 x2 -- x2 Drop the first item below the top of stack
1148 \ https://forth-standard.org/standard/core/Div
1149 \ / n1 n2 -- n3 signed quotient
1151 >R DUP 0< R> FM/MOD NIP
1155 [UNDEFINED] NEGATE [IF]
1156 \ https://forth-standard.org/standard/core/NEGATE
1157 \ C NEGATE x1 -- x2 two's complement
1165 [UNDEFINED] HERE [IF]
1171 [UNDEFINED] CHARS [IF]
1172 \ https://forth-standard.org/standard/core/CHARS
1173 \ CHARS n1 -- n2 chars->adrs units
1179 [UNDEFINED] MOVE [IF]
1180 \ https://forth-standard.org/standard/core/MOVE
1181 \ MOVE addr1 addr2 u -- smart move
1182 \ VERSION FOR 1 ADDRESS UNIT = 1 CHAR
1185 MOV @PSP+,Y \ Y = addr2 = dst
1186 MOV @PSP+,X \ X = addr1 = src
1187 MOV @PSP+,TOS \ pop new TOS
1188 CMP #0,W \ count = 0 ?
1189 0<> IF \ if 0, already done !
1190 CMP X,Y \ Y-X \ dst - src
1191 0<> IF \ else already done !
1192 U< IF \ U< if src > dst
1193 BEGIN \ copy W bytes
1198 MOV @IP+,PC \ out 1 of MOVE ====>
1199 THEN \ U>= if dst > src
1200 ADD W,Y \ copy W bytes beginning with the end
1210 MOV @IP+,PC \ out 2 of MOVE ====>
1214 [UNDEFINED] DECIMAL [IF]
1215 \ https://forth-standard.org/standard/core/DECIMAL
1222 [UNDEFINED] BASE [IF]
1223 \ https://forth-standard.org/standard/core/BASE
1224 \ BASE -- a-addr holds conversion radix
1225 BASEADR CONSTANT BASE
1229 \ https://forth-standard.org/standard/core/p
1230 \ ( -- skip input until char ) or EOL
1236 [UNDEFINED] .( [IF] \ "
1237 \ https://forth-standard.org/standard/core/Dotp
1238 \ .( -- type comment immediatly.
1240 MOV #0,&CAPS \ CAPS OFF
1244 $20 CAPS ! \ CAPS ON
1249 \ ==============================================================================
1251 \ ==============================================================================
1253 \ From: John Hayes S1I
1254 \ Subject: tester.fr
1255 \ Date: Mon, 27 Nov 95 13:10:09 PST
1257 \ (C) 1995 JOHNS HOPKINS UNIVERSITY / APPLIED PHYSICS LABORATORY
1258 \ MAY BE DISTRIBUTED FREELY AS LONG AS THIS COPYRIGHT NOTICE REMAINS.
1261 \ 22/1/09 The words { and } have been changed to T{ and }T respectively to
1262 \ agree with the Forth 200X file ttester.fs. This avoids clashes with
1263 \ locals using { ... } and the FSL use of }
1266 \ 13/05/14 jmt. added colorised error messages.
1270 \ SET THE FOLLOWING FLAG TO TRUE FOR MORE VERBOSE OUTPUT; THIS MAY
1271 \ ALLOW YOU TO TELL WHICH TEST CAUSED YOUR SYSTEM TO HANG.
1276 \ : EMPTY-STACK ( ... -- ) \ EMPTY STACK: HANDLES UNDERFLOWED STACK TOO.
1278 \ IF DUP 0< IF NEGATE 0
1280 \ ELSE 0 DO DROP LOOP THEN
1283 \ : ERROR \ ( C-ADDR U -- ) DISPLAY AN ERROR MESSAGE FOLLOWED BY
1284 \ \ THE LINE THAT HAD THE ERROR.
1285 \ TYPE SOURCE TYPE CR \ DISPLAY LINE CORRESPONDING TO ERROR
1286 \ EMPTY-STACK \ THROW AWAY EVERY THING ELSE
1287 \ QUIT \ *** Uncomment this line to QUIT on an error
1290 VARIABLE ACTUAL-DEPTH \ STACK RECORD
1291 CREATE ACTUAL-RESULTS 20 CELLS ALLOT
1293 : T{ \ ( -- ) SYNTACTIC SUGAR.
1296 : -> \ ( ... -- ) RECORD DEPTH AND CONTENT OF STACK.
1297 DEPTH DUP ACTUAL-DEPTH ! \ RECORD DEPTH
1298 ?DUP IF \ IF THERE IS SOMETHING ON STACK
1299 0 DO ACTUAL-RESULTS I CELLS + ! LOOP \ SAVE THEM
1302 : }T \ ( ... -- ) COMPARE STACK (EXPECTED) CONTENTS WITH SAVED
1303 \ (ACTUAL) CONTENTS.
1304 DEPTH ACTUAL-DEPTH @ = IF \ IF DEPTHS MATCH
1305 DEPTH ?DUP IF \ IF THERE IS SOMETHING ON THE STACK
1306 0 DO \ FOR EACH STACK ITEM
1307 ACTUAL-RESULTS I CELLS + @ \ COMPARE ACTUAL WITH EXPECTED
1308 \ = 0= IF S" INCORRECT RESULT: " ERROR LEAVE THEN \ jmt
1309 = 0= IF TRUE ABORT" INCORRECT RESULT" THEN \ jmt : abort with colorised message
1312 ELSE \ DEPTH MISMATCH
1313 \ S" WRONG NUMBER OF RESULTS: " ERROR \ jmt
1314 TRUE ABORT" WRONG NUMBER OF RESULTS" \ jmt : abort with colorised message
1317 : TESTING \ ( -- ) TALKING COMMENT.
1319 IF DUP >R TYPE CR R> >IN !
1320 ELSE >IN ! DROP [CHAR] * EMIT
1325 \ ==============================================================================
1327 \ ==============================================================================
1328 \ https://raw.githubusercontent.com/gerryjackson/forth2012-test-suite/master/src/doubletest.fth
1330 \ To test the ANS Forth Double-Number word set and double number extensions
1332 \ This program was written by Gerry Jackson in 2006, with contributions from
1333 \ others where indicated, and is in the public domain - it can be distributed
1334 \ and/or modified in any way but please retain this notice.
1336 \ This program is distributed in the hope that it will be useful,
1337 \ but WITHOUT ANY WARRANTY; without even the implied warranty of
1338 \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1340 \ The tests are not claimed to be comprehensive or correct
1341 \ ------------------------------------------------------------------------------
1342 \ Version 0.13 Assumptions and dependencies changed
1343 \ 0.12 1 August 2015 test D< acts on MS cells of double word
1344 \ 0.11 7 April 2015 2VALUE tested
1345 \ 0.6 1 April 2012 Tests placed in the public domain.
1346 \ Immediate 2CONSTANTs and 2VARIABLEs tested
1347 \ 0.5 20 November 2009 Various constants renamed to avoid
1348 \ redefinition warnings. <TRUE> and <FALSE> replaced
1349 \ with TRUE and FALSE
1350 \ 0.4 6 March 2009 { and } replaced with T{ and }T
1351 \ Tests rewritten to be independent of word size and
1353 \ 0.3 20 April 2007 ANS Forth words changed to upper case
1354 \ 0.2 30 Oct 2006 Updated following GForth test to include
1355 \ various constants from core.fr
1356 \ 0.1 Oct 2006 First version released
1357 \ ------------------------------------------------------------------------------
1358 \ The tests are based on John Hayes test program for the core word set
1360 \ Words tested in this file are:
1361 \ 2CONSTANT 2LITERAL 2VARIABLE D+ D- D. D.R D0< D0= D2* D2/
1362 \ D< D= D>S DABS DMAX DMIN DNEGATE M*/ M+ 2ROT DU<
1363 \ Also tests the interpreter and compiler reading a double number
1364 \ ------------------------------------------------------------------------------
1365 \ Assumptions and dependencies:
1366 \ - tester.fr (or ttester.fs), errorreport.fth and utilities.fth have been
1367 \ included prior to this file
1368 \ - the Core word set is available and tested
1369 \ ------------------------------------------------------------------------------
1370 \ Constant definitions
1374 0 INVERT CONSTANT 1SD
1375 1SD 1 RSHIFT CONSTANT MAX-INTD \ 01...1
1376 MAX-INTD INVERT CONSTANT MIN-INTD \ 10...0
1377 MAX-INTD 2/ CONSTANT HI-INT \ 001...1
1378 MIN-INTD 2/ CONSTANT LO-INT \ 110...1
1386 \ ------------------------------------------------------------------------------
1387 TESTING interpreter and compiler reading double numbers, with/without prefixes
1391 T{ : RDL1 3. ; RDL1 -> 3 0 }T
1392 T{ : RDL2 -4. ; RDL2 -> -4 -1 }T
1395 DECIMAL BASE @ OLD-DBASE !
1396 T{ #12346789. -> 12346789. }T
1397 T{ #-12346789. -> -12346789. }T
1398 T{ $12aBcDeF. -> 313249263. }T
1399 T{ $-12AbCdEf. -> -313249263. }T
1400 T{ %10010110. -> 150. }T
1401 T{ %-10010110. -> -150. }T
1402 \ Check BASE is unchanged
1403 T{ BASE @ OLD-DBASE @ = -> TRUE }T
1405 \ Repeat in Hex mode
1406 16 OLD-DBASE ! 16 BASE !
1407 T{ #12346789. -> BC65A5. }T
1408 T{ #-12346789. -> -BC65A5. }T
1409 T{ $12aBcDeF. -> 12AbCdeF. }T
1410 T{ $-12AbCdEf. -> -12ABCDef. }T
1411 T{ %10010110. -> 96. }T
1412 T{ %-10010110. -> -96. }T
1413 \ Check BASE is unchanged
1414 T{ BASE @ OLD-DBASE @ = -> TRUE }T \ 2
1417 \ Check number prefixes in compile mode
1418 T{ : dnmp #8327. $-2cbe. %011010111. ; dnmp -> 8327. -11454. 215. }T
1420 \ ------------------------------------------------------------------------------
1423 T{ 1 2 2CONSTANT 2C1 -> }T
1425 T{ : CD1 2C1 ; -> }T
1427 T{ : CD2 2CONSTANT ; -> }T
1428 T{ -1 -2 CD2 2C2 -> }T
1430 T{ 4 5 2CONSTANT 2C3 IMMEDIATE 2C3 -> 4 5 }T
1431 T{ : CD6 2C3 2LITERAL ; CD6 -> 4 5 }T
1433 \ ------------------------------------------------------------------------------
1434 \ Some 2CONSTANTs for the following tests
1436 1SD MAX-INTD 2CONSTANT MAX-2INT \ 01...1
1437 0 MIN-INTD 2CONSTANT MIN-2INT \ 10...0
1438 MAX-2INT 2/ 2CONSTANT HI-2INT \ 001...1
1439 MIN-2INT 2/ 2CONSTANT LO-2INT \ 110...0
1441 \ ------------------------------------------------------------------------------
1444 T{ 0. DNEGATE -> 0. }T
1445 T{ 1. DNEGATE -> -1. }T
1446 T{ -1. DNEGATE -> 1. }T
1447 T{ MAX-2INT DNEGATE -> MIN-2INT SWAP 1+ SWAP }T
1448 T{ MIN-2INT SWAP 1+ SWAP DNEGATE -> MAX-2INT }T
1450 \ ------------------------------------------------------------------------------
1451 TESTING D+ with small integers
1453 T{ 0. 5. D+ -> 5. }T
1454 T{ -5. 0. D+ -> -5. }T
1455 T{ 1. 2. D+ -> 3. }T
1456 T{ 1. -2. D+ -> -1. }T
1457 T{ -1. 2. D+ -> 1. }T
1458 T{ -1. -2. D+ -> -3. }T
1459 T{ -1. 1. D+ -> 0. }T
1461 TESTING D+ with mid range integers
1463 T{ 0 0 0 5 D+ -> 0 5 }T
1464 T{ -1 5 0 0 D+ -> -1 5 }T
1465 T{ 0 0 0 -5 D+ -> 0 -5 }T
1466 T{ 0 -5 -1 0 D+ -> -1 -5 }T
1467 T{ 0 1 0 2 D+ -> 0 3 }T
1468 T{ -1 1 0 -2 D+ -> -1 -1 }T
1469 T{ 0 -1 0 2 D+ -> 0 1 }T
1470 T{ 0 -1 -1 -2 D+ -> -1 -3 }T
1471 T{ -1 -1 0 1 D+ -> -1 0 }T
1472 T{ MIN-INTD 0 2DUP D+ -> 0 1 }T
1473 T{ MIN-INTD S>D MIN-INTD 0 D+ -> 0 0 }T
1475 TESTING D+ with large double integers
1477 T{ HI-2INT 1. D+ -> 0 HI-INT 1+ }T
1478 T{ HI-2INT 2DUP D+ -> 1SD 1- MAX-INTD }T
1479 T{ MAX-2INT MIN-2INT D+ -> -1. }T
1480 T{ MAX-2INT LO-2INT D+ -> HI-2INT }T
1481 T{ HI-2INT MIN-2INT D+ 1. D+ -> LO-2INT }T
1482 T{ LO-2INT 2DUP D+ -> MIN-2INT }T
1484 \ ------------------------------------------------------------------------------
1485 TESTING D- with small integers
1487 T{ 0. 5. D- -> -5. }T
1488 T{ 5. 0. D- -> 5. }T
1489 T{ 0. -5. D- -> 5. }T
1490 T{ 1. 2. D- -> -1. }T
1491 T{ 1. -2. D- -> 3. }T
1492 T{ -1. 2. D- -> -3. }T
1493 T{ -1. -2. D- -> 1. }T
1494 T{ -1. -1. D- -> 0. }T
1496 TESTING D- with mid-range integers
1498 T{ 0 0 0 5 D- -> 0 -5 }T
1499 T{ -1 5 0 0 D- -> -1 5 }T
1500 T{ 0 0 -1 -5 D- -> 1 4 }T
1501 T{ 0 -5 0 0 D- -> 0 -5 }T
1502 T{ -1 1 0 2 D- -> -1 -1 }T
1503 T{ 0 1 -1 -2 D- -> 1 2 }T
1504 T{ 0 -1 0 2 D- -> 0 -3 }T
1505 T{ 0 -1 0 -2 D- -> 0 1 }T
1506 T{ 0 0 0 1 D- -> 0 -1 }T
1507 T{ MIN-INTD 0 2DUP D- -> 0. }T
1508 T{ MIN-INTD S>D MAX-INTD 0 D- -> 1 1SD }T
1510 TESTING D- with large integers
1512 T{ MAX-2INT MAX-2INT D- -> 0. }T
1513 T{ MIN-2INT MIN-2INT D- -> 0. }T
1514 T{ MAX-2INT HI-2INT D- -> LO-2INT DNEGATE }T
1515 T{ HI-2INT LO-2INT D- -> MAX-2INT }T
1516 T{ LO-2INT HI-2INT D- -> MIN-2INT 1. D+ }T
1517 T{ MIN-2INT MIN-2INT D- -> 0. }T
1518 T{ MIN-2INT LO-2INT D- -> LO-2INT }T
1520 \ ------------------------------------------------------------------------------
1523 T{ 0. D0< -> FALSE }T
1524 T{ 1. D0< -> FALSE }T
1525 T{ MIN-INTD 0 D0< -> FALSE }T
1526 T{ 0 MAX-INTD D0< -> FALSE }T
1527 T{ MAX-2INT D0< -> FALSE }T
1528 T{ -1. D0< -> TRUE }T
1529 T{ MIN-2INT D0< -> TRUE }T
1531 T{ 1. D0= -> FALSE }T
1532 T{ MIN-INTD 0 D0= -> FALSE }T
1533 T{ MAX-2INT D0= -> FALSE }T
1534 T{ -1 MAX-INTD D0= -> FALSE }T
1535 T{ 0. D0= -> TRUE }T
1536 T{ -1. D0= -> FALSE }T
1537 T{ 0 MIN-INTD D0= -> FALSE }T
1539 \ ------------------------------------------------------------------------------
1542 T{ 0. D2* -> 0. D2* }T
1543 T{ MIN-INTD 0 D2* -> 0 1 }T
1544 T{ HI-2INT D2* -> MAX-2INT 1. D- }T
1545 T{ LO-2INT D2* -> MIN-2INT }T
1549 T{ 0 1 D2/ -> MIN-INTD 0 }T
1550 T{ MAX-2INT D2/ -> HI-2INT }T
1551 T{ -1. D2/ -> -1. }T
1552 T{ MIN-2INT D2/ -> LO-2INT }T
1554 \ ------------------------------------------------------------------------------
1557 T{ 0. 1. D< -> TRUE }T
1558 T{ 0. 0. D< -> FALSE }T
1559 T{ 1. 0. D< -> FALSE }T
1560 T{ -1. 1. D< -> TRUE }T
1561 T{ -1. 0. D< -> TRUE }T
1562 T{ -2. -1. D< -> TRUE }T
1563 T{ -1. -2. D< -> FALSE }T
1564 T{ 0 1 1. D< -> FALSE }T \ Suggested by Helmut Eller
1565 T{ 1. 0 1 D< -> TRUE }T
1566 T{ 0 -1 1 -2 D< -> FALSE }T
1567 T{ 1 -2 0 -1 D< -> TRUE }T
1568 T{ -1. MAX-2INT D< -> TRUE }T
1569 T{ MIN-2INT MAX-2INT D< -> TRUE }T
1570 T{ MAX-2INT -1. D< -> FALSE }T
1571 T{ MAX-2INT MIN-2INT D< -> FALSE }T
1572 T{ MAX-2INT 2DUP -1. D+ D< -> FALSE }T
1573 T{ MIN-2INT 2DUP 1. D+ D< -> TRUE }T
1574 T{ MAX-INTD S>D 2DUP 1. D+ D< -> TRUE }T \ Ensure D< acts on MS cells
1576 T{ -1. -1. D= -> TRUE }T
1577 T{ -1. 0. D= -> FALSE }T
1578 T{ -1. 1. D= -> FALSE }T
1579 T{ 0. -1. D= -> FALSE }T
1580 T{ 0. 0. D= -> TRUE }T
1581 T{ 0. 1. D= -> FALSE }T
1582 T{ 1. -1. D= -> FALSE }T
1583 T{ 1. 0. D= -> FALSE }T
1584 T{ 1. 1. D= -> TRUE }T
1586 T{ 0 -1 0 -1 D= -> TRUE }T
1587 T{ 0 -1 0 0 D= -> FALSE }T
1588 T{ 0 -1 0 1 D= -> FALSE }T
1589 T{ 0 0 0 -1 D= -> FALSE }T
1590 T{ 0 0 0 0 D= -> TRUE }T
1591 T{ 0 0 0 1 D= -> FALSE }T
1592 T{ 0 1 0 -1 D= -> FALSE }T
1593 T{ 0 1 0 0 D= -> FALSE }T
1594 T{ 0 1 0 1 D= -> TRUE }T
1596 T{ MAX-2INT MIN-2INT D= -> FALSE }T
1597 T{ MAX-2INT 0. D= -> FALSE }T
1598 T{ MAX-2INT MAX-2INT D= -> TRUE }T
1599 T{ MAX-2INT HI-2INT D= -> FALSE }T
1600 T{ MAX-2INT MIN-2INT D= -> FALSE }T
1601 T{ MIN-2INT MIN-2INT D= -> TRUE }T
1602 T{ MIN-2INT LO-2INT D= -> FALSE }T
1603 T{ MIN-2INT MAX-2INT D= -> FALSE }T
1605 \ ------------------------------------------------------------------------------
1606 TESTING 2LITERAL 2VARIABLE
1608 T{ : CD3 [ MAX-2INT ] 2LITERAL ; -> }T
1609 T{ CD3 -> MAX-2INT }T
1610 T{ 2VARIABLE 2V1 -> }T
1613 T{ -1 -2 2V1 2! -> }T
1614 T{ 2V1 2@ -> -1 -2 }T
1615 T{ : CD4 2VARIABLE ; -> }T
1617 T{ : CD5 2V2 2! ; -> }T
1619 T{ 2V2 2@ -> -2 -1 }T
1620 T{ 2VARIABLE 2V3 IMMEDIATE 5 6 2V3 2! -> }T
1622 T{ : CD7 2V3 [ 2@ ] 2LITERAL ; CD7 -> 5 6 }T
1623 T{ : CD8 [ 6 7 ] 2V3 [ 2! ] ; 2V3 2@ -> 6 7 }T
1625 \ ------------------------------------------------------------------------------
1628 T{ 1. 2. DMAX -> 2. }T
1629 T{ 1. 0. DMAX -> 1. }T
1630 T{ 1. -1. DMAX -> 1. }T
1631 T{ 1. 1. DMAX -> 1. }T
1632 T{ 0. 1. DMAX -> 1. }T
1633 T{ 0. -1. DMAX -> 0. }T
1634 T{ -1. 1. DMAX -> 1. }T
1635 T{ -1. -2. DMAX -> -1. }T
1637 T{ MAX-2INT HI-2INT DMAX -> MAX-2INT }T
1638 T{ MAX-2INT MIN-2INT DMAX -> MAX-2INT }T
1639 T{ MIN-2INT MAX-2INT DMAX -> MAX-2INT }T
1640 T{ MIN-2INT LO-2INT DMAX -> LO-2INT }T
1642 T{ MAX-2INT 1. DMAX -> MAX-2INT }T
1643 T{ MAX-2INT -1. DMAX -> MAX-2INT }T
1644 T{ MIN-2INT 1. DMAX -> 1. }T
1645 T{ MIN-2INT -1. DMAX -> -1. }T
1648 T{ 1. 2. DMIN -> 1. }T
1649 T{ 1. 0. DMIN -> 0. }T
1650 T{ 1. -1. DMIN -> -1. }T
1651 T{ 1. 1. DMIN -> 1. }T
1652 T{ 0. 1. DMIN -> 0. }T
1653 T{ 0. -1. DMIN -> -1. }T
1654 T{ -1. 1. DMIN -> -1. }T
1655 T{ -1. -2. DMIN -> -2. }T
1657 T{ MAX-2INT HI-2INT DMIN -> HI-2INT }T
1658 T{ MAX-2INT MIN-2INT DMIN -> MIN-2INT }T
1659 T{ MIN-2INT MAX-2INT DMIN -> MIN-2INT }T
1660 T{ MIN-2INT LO-2INT DMIN -> MIN-2INT }T
1662 T{ MAX-2INT 1. DMIN -> 1. }T
1663 T{ MAX-2INT -1. DMIN -> -1. }T
1664 T{ MIN-2INT 1. DMIN -> MIN-2INT }T
1665 T{ MIN-2INT -1. DMIN -> MIN-2INT }T
1667 \ ------------------------------------------------------------------------------
1670 T{ 1234 0 D>S -> 1234 }T
1671 T{ -1234 -1 D>S -> -1234 }T
1672 T{ MAX-INTD 0 D>S -> MAX-INTD }T
1673 T{ MIN-INTD -1 D>S -> MIN-INTD }T
1676 T{ -1. DABS -> 1. }T
1677 T{ MAX-2INT DABS -> MAX-2INT }T
1678 T{ MIN-2INT 1. D+ DABS -> MAX-2INT }T
1680 \ ------------------------------------------------------------------------------
1683 T{ HI-2INT 1 M+ -> HI-2INT 1. D+ }T
1684 T{ MAX-2INT -1 M+ -> MAX-2INT -1. D+ }T
1685 T{ MIN-2INT 1 M+ -> MIN-2INT 1. D+ }T
1686 T{ LO-2INT -1 M+ -> LO-2INT -1. D+ }T
1688 \ To correct the result if the division is floored, only used when
1689 \ necessary i.e. negative quotient and remainder <> 0
1691 : ?FLOORED [ -3 2 / -2 = ] LITERAL IF 1. D- THEN ;
1693 T{ 5. 7 11 M*/ -> 3. }T
1694 T{ 5. -7 11 M*/ -> -3. ?FLOORED }T \ FLOORED -4.
1695 T{ -5. 7 11 M*/ -> -3. ?FLOORED }T \ FLOORED -4.
1696 T{ -5. -7 11 M*/ -> 3. }T
1697 T{ MAX-2INT 8 16 M*/ -> HI-2INT }T
1698 T{ MAX-2INT -8 16 M*/ -> HI-2INT DNEGATE ?FLOORED }T \ FLOORED SUBTRACT 1
1699 T{ MIN-2INT 8 16 M*/ -> LO-2INT }T
1700 T{ MIN-2INT -8 16 M*/ -> LO-2INT DNEGATE }T
1701 T{ MAX-2INT MAX-INTD MAX-INTD M*/ -> MAX-2INT }T
1702 T{ MAX-2INT MAX-INTD 2/ MAX-INTD M*/ -> MAX-INTD 1- HI-2INT NIP }T
1703 T{ MIN-2INT LO-2INT NIP 1+ DUP 1- NEGATE M*/ -> 0 MAX-INTD 1- }T
1704 T{ MIN-2INT LO-2INT NIP 1- MAX-INTD M*/ -> MIN-INTD 3 + HI-2INT NIP 2 + }T
1705 T{ MAX-2INT LO-2INT NIP DUP NEGATE M*/ -> MAX-2INT DNEGATE }T
1706 T{ MIN-2INT MAX-INTD DUP M*/ -> MIN-2INT }T
1708 \ ------------------------------------------------------------------------------
1711 \ Create some large double numbers
1712 MAX-2INT 71 73 M*/ 2CONSTANT DBL1
1713 MIN-2INT 73 79 M*/ 2CONSTANT DBL2
1715 : D>ASCII ( D -- CADDR U )
1716 DUP >R <# DABS #S R> SIGN #> ( -- CADDR1 U )
1717 HERE SWAP 2DUP 2>R CHARS DUP ALLOT MOVE 2R>
1720 DBL1 D>ASCII 2CONSTANT "DBL1"
1721 DBL2 D>ASCII 2CONSTANT "DBL2"
1724 CR ." You should see lines duplicated:" CR
1725 5 SPACES "DBL1" TYPE CR
1727 8 SPACES "DBL1" DUP >R TYPE CR
1728 5 SPACES DBL1 R> 3 + D.R CR
1729 5 SPACES "DBL2" TYPE CR
1731 10 SPACES "DBL2" DUP >R TYPE CR
1732 5 SPACES DBL2 R> 5 + D.R CR
1735 T{ DOUBLEOUTPUT -> }T
1737 \ ------------------------------------------------------------------------------
1738 TESTING 2ROT DU< (Double Number extension words)
1740 T{ 1. 2. 3. 2ROT -> 2. 3. 1. }T
1741 T{ MAX-2INT MIN-2INT 1. 2ROT -> MIN-2INT 1. MAX-2INT }T
1743 T{ 1. 1. DU< -> FALSE }T
1744 T{ 1. -1. DU< -> TRUE }T
1745 T{ -1. 1. DU< -> FALSE }T
1746 T{ -1. -2. DU< -> FALSE }T
1747 T{ 0 1 1. DU< -> FALSE }T
1748 T{ 1. 0 1 DU< -> TRUE }T
1749 T{ 0 -1 1 -2 DU< -> FALSE }T
1750 T{ 1 -2 0 -1 DU< -> TRUE }T
1752 T{ MAX-2INT HI-2INT DU< -> FALSE }T
1753 T{ HI-2INT MAX-2INT DU< -> TRUE }T
1754 T{ MAX-2INT MIN-2INT DU< -> TRUE }T
1755 T{ MIN-2INT MAX-2INT DU< -> FALSE }T
1756 T{ MIN-2INT LO-2INT DU< -> TRUE }T
1758 \ ------------------------------------------------------------------------------
1761 T{ 1111 2222 2VALUE 2VAL -> }T
1762 T{ 2VAL -> 1111 2222 }T
1763 T{ 3333 4444 TO 2VAL -> }T
1764 T{ 2VAL -> 3333 4444 }T
1765 T{ : TO-2VAL TO 2VAL ; 5555 6666 TO-2VAL -> }T
1766 T{ 2VAL -> 5555 6666 }T
1768 \ ------------------------------------------------------------------------------
1770 CR .( End of Double-Number word tests) CR