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
12 \ from scite editor : copy your target selection in (shift+F8) parameter 1:
16 \ drag and drop this file onto SendSourceFileToTarget.bat
17 \ then select your TARGET when asked.
21 \ rDODOES to rEXIT must be saved before use and restored after
22 \ scratch registers Y to S are free for use
23 \ under interrupt, IP is free for use
25 \ FORTH conditionnals: unary{ 0= 0< 0> }, binary{ = < > U< }
27 \ 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<
37 0<> IF MOV #0,TOS THEN \ if TOS <> 0 (DOUBLE input), set TOS = 0
40 SUB #400,TOS \ FastForth V4.0
42 $0D EMIT \ return to column 1 without CR
43 ABORT" FastForth V4.0 please!"
44 ABORT" build FastForth with DOUBLE_INPUT addon!"
45 RST_RET \ if no abort remove this word
50 ; -----------------------------------------------------
52 ; -----------------------------------------------------
56 [UNDEFINED] {DOUBLE} [IF]
59 ; ------------------------------------------------------------------
60 ; first we download the set of definitions we need (from CORE_ANS)
61 ; ------------------------------------------------------------------
64 \ https://forth-standard.org/standard/core/toR
65 \ >R x -- R: -- x push to return stack
74 \ https://forth-standard.org/standard/core/Rfrom
75 \ R> -- x R: x -- pop from return stack ; CALL #RFROM performs DOVAR
85 \ https://forth-standard.org/standard/core/Zeroless
86 \ 0< n -- flag true if TOS negative
88 ADD TOS,TOS \ 1 set carry if TOS negative
89 SUBC TOS,TOS \ 1 TOS=-1 if carry was clear
90 XOR #-1,TOS \ 1 TOS=-1 if carry was set
96 \ https://forth-standard.org/standard/core/DROP
97 \ DROP x -- drop top of stack
105 \ https://forth-standard.org/standard/core/DUP
106 \ DUP x -- x x duplicate top of stack
108 BW1 SUB #2,PSP \ 2 push old TOS..
109 MOV TOS,0(PSP) \ 3 ..onto stack
114 \ https://forth-standard.org/standard/core/qDUP
115 \ ?DUP x -- 0 | x x DUP if nonzero
116 CMP #0,TOS \ 2 test for TOS nonzero
123 \ https://forth-standard.org/standard/core/NIP
124 \ NIP x1 x2 -- x2 Drop the first item below the top of stack
131 [UNDEFINED] UM/MOD [IF]
132 \ https://forth-standard.org/standard/core/UMDivMOD
133 \ UM/MOD udlo|udhi u1 -- r q unsigned 32/16->r16 q16
136 MOV #MUSMOD,PC \ execute MUSMOD then return to DROP
140 KERNEL_ADDON @ 0< ; test the switch: FLOORED/SYMETRIC DIVISION
142 [UNDEFINED] FM/MOD [IF]
143 \ https://forth-standard.org/standard/core/FMDivMOD
144 \ FM/MOD d1 n1 -- r q floored signed div'n
148 CMP #0,TOS \ n2 >= 0 ?
151 ADD #1,TOS \ -- d1 u2
153 CMP #0,0(PSP) \ d1hi >= 0 ?
155 XOR #-1,2(PSP) \ d1lo
156 XOR #-1,0(PSP) \ d1hi
157 ADD #1,2(PSP) \ d1lo+1
158 ADDC #0,0(PSP) \ d1hi+C
159 THEN \ -- uDVDlo uDVDhi uDIVlo
160 PUSHM #3,IP \ save IP,S,T
162 UM/MOD \ -- uREMlo uQUOTlo
164 POPM #3,IP \ restore T,S,IP
165 CMP #0,T \ T=DVDhi --> REM_sign
170 XOR S,T \ S=DIV XOR T=DVDhi = Quot_sign
171 CMP #0,T \ -- n3 u4 T=quot_sign
175 THEN \ -- n3 n4 S=divisor
177 CMP #0,0(PSP) \ remainder <> 0 ?
179 CMP #1,TOS \ quotient < 1 ?
181 ADD S,0(PSP) \ add divisor to remainder
182 SUB #1,TOS \ decrement quotient
190 [UNDEFINED] SM/REM [IF]
191 \ https://forth-standard.org/standard/core/SMDivREM
192 \ SM/REM DVDlo DVDhi DIV -- r3 q4 symmetric signed div
196 CMP #0,TOS \ n2 >= 0 ?
199 ADD #1,TOS \ -- d1 u2
201 CMP #0,0(PSP) \ d1hi >= 0 ?
203 XOR #-1,2(PSP) \ d1lo
204 XOR #-1,0(PSP) \ d1hi
205 ADD #1,2(PSP) \ d1lo+1
206 ADDC #0,0(PSP) \ d1hi+C
207 THEN \ -- uDVDlo uDVDhi uDIVlo
208 PUSHM #3,IP \ save IP,S,T
210 UM/MOD \ -- uREMlo uQUOTlo
212 POPM #3,IP \ restore T,S,IP
213 CMP #0,T \ T=DVDhi --> REM_sign
218 XOR S,T \ S=DIV XOR T=DVDhi = Quot_sign
219 CMP #0,T \ -- n3 u4 T=quot_sign
223 THEN \ -- n3 n4 S=divisor
230 \ https://forth-standard.org/standard/core/Div
231 \ / n1 n2 -- n3 signed quotient
234 [ KERNEL_ADDON @ 0< ]
243 \ https://forth-standard.org/standard/core/CFetch
244 \ C@ c-addr -- char fetch char from memory
251 [UNDEFINED] SWAP [IF]
252 \ https://forth-standard.org/standard/core/SWAP
253 \ SWAP x1 x2 -- x2 x1 swap top two items
262 [UNDEFINED] OVER [IF]
263 \ https://forth-standard.org/standard/core/OVER
264 \ OVER x1 x2 -- x1 x2 x1
266 MOV TOS,-2(PSP) \ 3 -- x1 (x2) x2
267 MOV @PSP,TOS \ 2 -- x1 (x2) x1
268 SUB #2,PSP \ 1 -- x1 x2 x1
274 \ https://forth-standard.org/standard/core/ROT
275 \ ROT x1 x2 x3 -- x2 x3 x1
277 MOV @PSP,W \ 2 fetch x2
278 MOV TOS,0(PSP) \ 3 store x3
279 MOV 2(PSP),TOS \ 3 fetch x1
280 MOV W,2(PSP) \ 3 store x2
286 \ https://forth-standard.org/standard/core/Minus
287 \ - n1/u1 n2/u2 -- n3/u3 n3 = n1-n2
289 SUB @PSP+,TOS \ 2 -- n2-n1 ( = -n3)
291 ADD #1,TOS \ 1 -- n3 = -(n2-n1) = n1-n2
296 [UNDEFINED] < [IF] \ define < and >
297 \ https://forth-standard.org/standard/core/less
298 \ < n1 n2 -- flag test n1<n2, signed
300 SUB @PSP+,TOS \ 1 TOS=n2-n1
301 S< ?GOTO FW1 \ 2 signed
303 BW1 MOV #-1,TOS \ 1 flag Z = 0
308 \ https://forth-standard.org/standard/core/more
309 \ > n1 n2 -- flag test n1>n2, signed
311 SUB @PSP+,TOS \ 2 TOS=n2-n1
312 S< ?GOTO BW1 \ 2 --> +5
313 FW1 AND #0,TOS \ 1 flag Z = 1
318 [UNDEFINED] IF [IF] \ define IF THEN
319 \ https://forth-standard.org/standard/core/IF
320 \ IF -- IFadr initialize conditional forward branch
324 MOV &DP,TOS \ -- HERE
325 ADD #4,&DP \ compile one word, reserve one word
326 MOV #QFBRAN,0(TOS) \ -- HERE compile QFBRAN
327 ADD #2,TOS \ -- HERE+2=IFadr
331 \ https://forth-standard.org/standard/core/THEN
332 \ THEN IFadr -- resolve forward branch
333 CODE THEN \ immediate
334 MOV &DP,0(TOS) \ -- IFadr
340 [UNDEFINED] ELSE [IF]
341 \ https://forth-standard.org/standard/core/ELSE
342 \ ELSE IFadr -- ELSEadr resolve forward IF branch, leave ELSEadr on stack
343 CODE ELSE \ immediate
344 ADD #4,&DP \ make room to compile two words
347 MOV W,0(TOS) \ HERE+4 ==> [IFadr]
349 MOV W,TOS \ -- ELSEadr
355 \ https://forth-standard.org/standard/core/TO
362 [UNDEFINED] DOES> [IF]
363 \ https://forth-standard.org/standard/core/DOES
364 \ DOES> -- set action for the latest CREATEd definition
366 MOV &LAST_CFA,W \ W = CFA of CREATEd word
367 MOV #DODOES,0(W) \ replace CFA (CALL rDOCON) by new CFA (CALL rDODOES)
368 MOV IP,2(W) \ replace PFA by the address after DOES> as execution address
374 [UNDEFINED] SPACES [IF]
375 \ https://forth-standard.org/standard/core/SPACES
376 \ SPACES n -- output n spaces
390 MOV @PSP+,TOS \ -- drop n
396 \ https://forth-standard.org/standard/core/TwoFetch
397 \ 2@ a-addr -- x1 x2 fetch 2 cells ; the lower address will appear on top of stack
407 \ https://forth-standard.org/standard/core/TwoStore
408 \ 2! x1 x2 a-addr -- store 2 cells ; the top of stack is stored at the lower adr
417 [UNDEFINED] 2DUP [IF]
418 \ https://forth-standard.org/standard/core/TwoDUP
419 \ 2DUP x1 x2 -- x1 x2 x1 x2 dup top 2 cells
421 SUB #4,PSP \ -- x1 x x x2
422 MOV TOS,2(PSP) \ -- x1 x2 x x2
423 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x2
428 [UNDEFINED] 2DROP [IF]
429 \ https://forth-standard.org/standard/core/TwoDROP
430 \ 2DROP x1 x2 -- drop 2 cells
438 [UNDEFINED] 2SWAP [IF]
439 \ https://forth-standard.org/standard/core/TwoSWAP
440 \ 2SWAP x1 x2 x3 x4 -- x3 x4 x1 x2
442 MOV @PSP,W \ -- x1 x2 x3 x4 W=x3
443 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x4
444 MOV W,4(PSP) \ -- x3 x2 x1 x4
445 MOV TOS,W \ -- x3 x2 x1 x4 W=x4
446 MOV 2(PSP),TOS \ -- x3 x2 x1 x2 W=x4
447 MOV W,2(PSP) \ -- x3 x4 x1 x2
452 [UNDEFINED] 2OVER [IF]
453 \ https://forth-standard.org/standard/core/TwoOVER
454 \ 2OVER x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2
456 SUB #4,PSP \ -- x1 x2 x3 x x x4
457 MOV TOS,2(PSP) \ -- x1 x2 x3 x4 x x4
458 MOV 8(PSP),0(PSP) \ -- x1 x2 x3 x4 x1 x4
459 MOV 6(PSP),TOS \ -- x1 x2 x3 x4 x1 x2
465 \ https://forth-standard.org/standard/core/TwotoR
466 \ ( x1 x2 -- ) ( R: -- x1 x2 ) Transfer cell pair x1 x2 to the return stack.
476 \ https://forth-standard.org/standard/core/TwoRFetch
477 \ ( -- x1 x2 ) ( R: x1 x2 -- x1 x2 ) Copy cell pair x1 x2 from the return stack.
488 \ https://forth-standard.org/standard/core/TwoRfrom
489 \ ( -- x1 x2 ) ( R: x1 x2 -- ) Transfer cell pair x1 x2 from the return stack
499 ; --------------------------
500 ; end of definitions we need
501 ; --------------------------
503 ; ===============================================
505 ; ===============================================
508 \ https://forth-standard.org/standard/double/Dd
509 \ D. dlo dhi -- display d (signed)
511 MOV TOS,S \ S will be pushed as sign by DDOT
512 MOV #D.,PC \ U. + 10 = DDOT
516 [UNDEFINED] 2ROT [IF]
517 \ https://forth-standard.org/standard/double/TwoROT
518 \ Rotate the top three cell pairs on the stack bringing cell pair x1 x2 to the top of the stack.
522 MOV 4(PSP),8(PSP) \ 5
523 MOV 2(PSP),6(PSP) \ 5
533 \ https://forth-standard.org/standard/double/DtoS
534 \ D>S d -- n double prec -> single.
541 [UNDEFINED] D0= [IF] \ define: D0= D0< D= D< DU<
543 \ https://forth-standard.org/standard/double/DZeroEqual
554 BW2 AND #-1,TOS \ to set N, Z flags
558 \ https://forth-standard.org/standard/double/DZeroless
567 \ https://forth-standard.org/standard/double/DEqual
570 CMP TOS,-4(PSP) \ 3 ud1H - ud2H
573 CMP -6(PSP),-2(PSP) \ 4 ud1L - ud2L
578 \ https://forth-standard.org/standard/double/Dless
579 \ flag is true if and only if d1 is less than d2
582 CMP TOS,-4(PSP) \ 3 d1H - d2H
587 BW3 0<> ?GOTO BW2 \ 2
588 CMP -6(PSP),-2(PSP) \ 4 d1L - d2L
589 U>= ?GOTO BW2 \ to set N, Z flags
593 \ https://forth-standard.org/standard/double/DUless
594 \ flag is true if and only if ud1 is less than ud2
597 CMP TOS,-4(PSP) \ 3 ud1H - ud2H
604 [UNDEFINED] D+ [IF] \ define: D+ M+
605 \ https://forth-standard.org/standard/double/DPlus
612 \ https://forth-standard.org/standard/double/MPlus
626 \ https://forth-standard.org/standard/double/DMinus
635 [UNDEFINED] DNEGATE [IF] \ define DNEGATE DABS
636 \ https://forth-standard.org/standard/double/DNEGATE
645 \ https://forth-standard.org/standard/double/DABS
646 \ DABS d1 -- |d1| absolute value
655 \ https://forth-standard.org/standard/double/DTwoDiv
664 \ https://forth-standard.org/standard/double/DTwoTimes
672 [UNDEFINED] DMAX [IF]
673 \ https://forth-standard.org/standard/double/DMAX
675 2OVER 2OVER \ -- d1 d2 d1 d2
677 2>R 2DROP 2R> \ -- d2
684 [UNDEFINED] DMIN [IF]
685 \ https://forth-standard.org/standard/double/DMIN
687 2OVER 2OVER \ -- d1 d2 d1 d2
691 2>R 2DROP 2R> \ -- d1 d2
697 \ https://forth-standard.org/standard/double/MTimesDiv
701 CODE TSTBIT \ addr bit_mask -- true/flase flag
707 KERNEL_ADDON HMPY TSTBIT \ hardware MPY ?
709 RST_RET \ remove TSTBIT definition
711 [IF] ; MSP430FRxxxx with hardware_MPY
713 CODE M*/ \ d1 * n1 / +n2 -- d2
714 MOV 4(PSP),&MPYS32L \ 5 Load 1st operand d1lo
715 MOV 2(PSP),&MPYS32H \ 5 d1hi
716 MOV @PSP+,&OP2 \ 4 -- d1 n2 load 2nd operand n1
719 MOV &RES0,S \ 3 S = RESlo
720 MOV &RES1,TOS \ 3 TOS = RESmi
721 MOV &RES2,W \ 3 W = REShi
722 MOV #0,rDOCON \ clear sign flag
723 CMP #0,W \ negative product ?
724 S< IF \ compute ABS value if yes
731 MOV #-1,rDOCON \ set sign flag
734 [ELSE] ; no hardware multiplier
736 CODE M*/ \ d1lo d1hi n1 +n2 -- d2lo d2hi
737 MOV #0,rDOCON \ rDOCON = sign
738 CMP #0,2(PSP) \ d1 < 0 ?
746 CMP #0,0(PSP) \ n1 < 0 ?
751 THEN \ let's process UM* -- ud1lo ud1hi u1 +n2
752 MOV 4(PSP),Y \ 3 uMDlo
753 MOV 2(PSP),T \ 3 uMDhi
754 MOV @PSP+,S \ 2 uMRlo -- ud1lo ud1hi +n2
755 MOV #0,rDODOES \ 1 uMDlo=0
756 MOV #0,2(PSP) \ 3 uRESlo=0
757 MOV #0,0(PSP) \ 3 uRESmi=0 -- uRESlo uRESmi +n2
758 MOV #0,W \ 1 uREShi=0
759 MOV #1,X \ 1 BIT TEST REGlo
760 BEGIN BIT X,S \ 1 test actual bit in uMRlo
761 0<> IF ADD Y,2(PSP) \ 3 IF 1: ADD uMDlo TO uRESlo
762 ADDC T,0(PSP) \ 3 ADDC uMDmi TO uRESmi
763 ADDC rDODOES,W \ 1 ADDC uMRlo TO uREShi
764 THEN ADD Y,Y \ 1 (RLA LSBs) uMDlo *2
765 ADDC T,T \ 1 (RLC MSBs) uMDhi *2
766 ADDC rDODOES,rDODOES \ 1 (RLA LSBs) uMDlo *2
767 ADD X,X \ 1 (RLA) NEXT BIT TO TEST
768 U>= UNTIL \ 1 IF BIT IN CARRY: FINISHED W=uREShi
777 [THEN] ; endcase of software/hardware_MPY
781 \ ------------------------------
786 \ X = Don't care QUOTlo
787 \ Y = Don't care QUOThi
793 MOV #32,rDODOES \ 2 init loop count
794 CMP #0,W \ DVDhi = 0 ?
796 MOV TOS,W \ DVDmi --> DVDhi
797 CALL #MDIV1DIV2 \ with loop count / 2
799 CALL #MDIV1 \ -- urem ud2lo ud2hi
801 MOV @PSP+,0(PSP) \ -- d2lo d2hi
802 CMP #0,rDOCON \ RES sign is set ?
803 0<> IF \ DNEGATE quot
808 CMP #0,&KERNEL_ADDON \ floored/symetric division flag test
809 S< IF \ if floored division and quot<0
810 CMP #0,W \ remainder <> 0 ?
811 0<> IF \ if floored division, quot<0 and remainder <>0
812 SUB #1,0(PSP) \ decrement quotient
819 MOV @IP+,PC \ 52 words
823 [UNDEFINED] 2VARIABLE [IF]
824 \ https://forth-standard.org/standard/double/TwoVARIABLE
834 [UNDEFINED] 2CONSTANT [IF]
835 \ https://forth-standard.org/standard/double/TwoCONSTANT
836 : 2CONSTANT \ udlo/dlo/Flo udhi/dhi/Shi -- to create double or s15q16 CONSTANT
838 , , \ compile hi then lo
844 [UNDEFINED] 2VALUE [IF]
845 \ https://forth-standard.org/standard/double/TwoVALUE
846 : 2VALUE \ x1 x2 "<spaces>name" --
847 CREATE , , \ compile Shi then Flo
851 BIT #UF9,SR \ flag set by TO
853 MOV #2@,PC \ execute TwoFetch
855 BIC #UF9,SR \ clear flag
856 MOV #2!,PC \ execute TwoStore
861 [UNDEFINED] 2LITERAL [IF]
862 \ https://forth-standard.org/standard/double/TwoLITERAL
864 BIS #UF9,SR \ see LITERAL
871 \ https://forth-standard.org/standard/double/DDotR
874 >R SWAP OVER DABS <# #S ROT SIGN #>
875 R> OVER - SPACES TYPE
881 [THEN] \ endof [UNDEFINED] {DOUBLE}
883 ; -------------------------------
884 ; Complement to pass DOUBLE TESTS
885 ; -------------------------------
887 [UNDEFINED] SWAP [IF]
888 \ https://forth-standard.org/standard/core/SWAP
889 \ SWAP x1 x2 -- x2 x1 swap top two items
898 [UNDEFINED] VARIABLE [IF]
899 \ https://forth-standard.org/standard/core/VARIABLE
900 \ VARIABLE <name> -- define a Forth VARIABLE
904 MOV #DOVAR,-4(W) \ CFA = CALL rDOVAR
910 [UNDEFINED] CONSTANT [IF]
911 \ https://forth-standard.org/standard/core/CONSTANT
912 \ CONSTANT <name> n -- define a Forth CONSTANT
916 MOV TOS,-2(W) \ PFA = n
923 [UNDEFINED] CELLS [IF]
924 \ https://forth-standard.org/standard/core/CELLS
925 \ CELLS n1 -- n2 cells->adrs units
932 [UNDEFINED] DEPTH [IF]
933 \ https://forth-standard.org/standard/core/DEPTH
934 \ DEPTH -- +n number of items on stack, must leave 0 if stack empty
938 SUB PSP,TOS \ PSP-S0--> TOS
939 RRA TOS \ TOS/2 --> TOS
940 SUB #2,PSP \ post decrement stack...
945 [UNDEFINED] IF [IF] \ define IF THEN
946 \ https://forth-standard.org/standard/core/IF
947 \ IF -- IFadr initialize conditional forward branch
951 MOV &DP,TOS \ -- HERE
952 ADD #4,&DP \ compile one word, reserve one word
953 MOV #QFBRAN,0(TOS) \ -- HERE compile QFBRAN
954 ADD #2,TOS \ -- HERE+2=IFadr
958 \ https://forth-standard.org/standard/core/THEN
959 \ THEN IFadr -- resolve forward branch
960 CODE THEN \ immediate
961 MOV &DP,0(TOS) \ -- IFadr
967 [UNDEFINED] ELSE [IF]
968 \ https://forth-standard.org/standard/core/ELSE
969 \ ELSE IFadr -- ELSEadr resolve forward IF branch, leave ELSEadr on stack
970 CODE ELSE \ immediate
971 ADD #4,&DP \ make room to compile two words
974 MOV W,0(TOS) \ HERE+4 ==> [IFadr]
976 MOV W,TOS \ -- ELSEadr
981 [UNDEFINED] DO [IF] \ define DO LOOP +LOOP
983 \ https://forth-standard.org/standard/core/DO
984 \ DO -- DOadr L: -- 0
985 HDNCODE XDO \ DO run time
986 MOV #$8000,X \ 2 compute 8000h-limit = "fudge factor"
988 MOV TOS,Y \ 1 loop ctr = index+fudge
989 ADD X,Y \ 1 Y = INDEX
990 PUSHM #2,X \ 4 PUSHM X,Y, i.e. PUSHM LIMIT, INDEX
998 ADD #2,&DP \ make room to compile xdo
999 MOV &DP,TOS \ -- HERE+2
1000 MOV #XDO,-2(TOS) \ compile xdo
1001 ADD #2,&LEAVEPTR \ -- HERE+2 LEAVEPTR+2
1003 MOV #0,0(W) \ -- HERE+2 L-- 0, init
1007 \ https://forth-standard.org/standard/core/LOOP
1008 \ LOOP DOadr -- L-- an an-1 .. a1 0
1009 HDNCODE XLOOP \ LOOP run time
1010 ADD #1,0(RSP) \ 4 increment INDEX
1011 BW1 BIT #$100,SR \ 2 is overflow bit set?
1012 0= IF \ branch if no overflow
1016 ADD #4,RSP \ 1 empties RSP
1017 ADD #2,IP \ 1 overflow = loop done, skip branch ofs
1018 MOV @IP+,PC \ 4 14~ taken or not taken xloop/loop
1023 BW2 ADD #4,&DP \ make room to compile two words
1025 MOV X,-4(W) \ xloop --> HERE
1026 MOV TOS,-2(W) \ DOadr --> HERE+2
1027 BEGIN \ resolve all "leave" adr
1028 MOV &LEAVEPTR,TOS \ -- Adr of top LeaveStack cell
1029 SUB #2,&LEAVEPTR \ --
1030 MOV @TOS,TOS \ -- first LeaveStack value
1031 CMP #0,TOS \ -- = value left by DO ?
1033 MOV W,0(TOS) \ move adr after loop as UNLOOP adr
1039 \ https://forth-standard.org/standard/core/PlusLOOP
1040 \ +LOOP adrs -- L-- an an-1 .. a1 0
1041 HDNCODE XPLOO \ +LOOP run time
1042 ADD TOS,0(RSP) \ 4 increment INDEX by TOS value
1043 MOV @PSP+,TOS \ 2 get new TOS, doesn't change flags
1054 \ https://forth-standard.org/standard/core/I
1055 \ I -- n R: sys1 sys2 -- sys1 sys2
1056 \ get the innermost loop index
1058 SUB #2,PSP \ 1 make room in TOS
1060 MOV @RSP,TOS \ 2 index = loopctr - fudge
1067 \ https://forth-standard.org/standard/core/Plus
1068 \ + n1/u1 n2/u2 -- n3/u3 add n1+n2
1076 \ https://forth-standard.org/standard/core/Equal
1077 \ = x1 x2 -- flag test x1=x2
1084 XOR #-1,TOS \ 1 flag Z = 1
1090 \ https://forth-standard.org/standard/core/ZeroEqual
1091 \ 0= n/u -- flag return true if TOS=0
1093 SUB #1,TOS \ borrow (clear cy) if TOS was 0
1094 SUBC TOS,TOS \ TOS=-1 if borrow was set
1099 [UNDEFINED] SOURCE [IF]
1100 \ https://forth-standard.org/standard/core/SOURCE
1101 \ SOURCE -- adr u of current input buffer
1106 MOV &SOURCE_ORG,0(PSP)
1111 [UNDEFINED] >IN [IF]
1112 \ https://forth-standard.org/standard/core/toIN
1113 \ C >IN -- a-addr holds offset in input stream
1118 \ https://forth-standard.org/standard/core/OnePlus
1119 \ 1+ n1/u1 -- n2/u2 add 1 to TOS
1126 [UNDEFINED] CHAR [IF]
1127 \ https://forth-standard.org/standard/core/CHAR
1128 \ CHAR -- char parse ASCII character
1134 [UNDEFINED] [CHAR] [IF]
1135 \ https://forth-standard.org/standard/core/BracketCHAR
1136 \ [CHAR] -- compile character literal
1138 CHAR POSTPONE LITERAL
1143 \ https://forth-standard.org/standard/core/TwoDiv
1144 \ 2/ x1 -- x2 arithmetic right shift
1151 [UNDEFINED] INVERT [IF]
1152 \ https://forth-standard.org/standard/core/INVERT
1153 \ INVERT x1 -- x2 bitwise inversion
1160 [UNDEFINED] RSHIFT [IF]
1161 \ https://forth-standard.org/standard/core/RSHIFT
1162 \ RSHIFT x1 u -- x2 logical R7 shift u places
1165 AND #$1F,TOS \ no need to shift more than 16
1168 BIC #C,SR \ Clr Carry
1178 [UNDEFINED] S>D [IF]
1179 \ https://forth-standard.org/standard/core/StoD
1180 \ S>D n -- d single -> double prec.
1187 \ https://forth-standard.org/standard/core/OneMinus
1188 \ 1- n1/u1 -- n2/u2 subtract 1 from TOS
1195 [UNDEFINED] NEGATE [IF]
1196 \ https://forth-standard.org/standard/core/NEGATE
1197 \ C NEGATE x1 -- x2 two's complement
1205 [UNDEFINED] HERE [IF]
1211 [UNDEFINED] CHARS [IF]
1212 \ https://forth-standard.org/standard/core/CHARS
1213 \ CHARS n1 -- n2 chars->adrs units
1219 [UNDEFINED] MOVE [IF]
1220 \ https://forth-standard.org/standard/core/MOVE
1221 \ MOVE addr1 addr2 u -- smart move
1222 \ VERSION FOR 1 ADDRESS UNIT = 1 CHAR
1225 MOV @PSP+,Y \ Y = addr2 = dst
1226 MOV @PSP+,X \ X = addr1 = src
1227 MOV @PSP+,TOS \ pop new TOS
1228 CMP #0,W \ count = 0 ?
1229 0<> IF \ if 0, already done !
1230 CMP X,Y \ Y-X \ dst - src
1231 0<> IF \ else already done !
1232 U< IF \ U< if src > dst
1233 BEGIN \ copy W bytes
1238 MOV @IP+,PC \ out 1 of MOVE ====>
1239 THEN \ U>= if dst > src
1240 ADD W,Y \ copy W bytes beginning with the end
1250 MOV @IP+,PC \ out 2 of MOVE ====>
1254 [UNDEFINED] DECIMAL [IF]
1255 \ https://forth-standard.org/standard/core/DECIMAL
1262 [UNDEFINED] BASE [IF]
1263 \ https://forth-standard.org/standard/core/BASE
1264 \ BASE -- a-addr holds conversion radix
1265 BASEADR CONSTANT BASE
1269 \ https://forth-standard.org/standard/core/p
1270 \ ( -- skip input until char ) or EOL
1276 [UNDEFINED] .( [IF] ; "
1277 \ https://forth-standard.org/standard/core/Dotp
1278 \ .( -- type comment immediatly.
1280 MOV #0,&CAPS \ CAPS OFF
1284 $20 CAPS ! \ CAPS ON
1289 \ https://forth-standard.org/standard/core/CR
1290 \ CR -- send CR+LF to the output device
1291 \ DEFER CR \ DEFERed definition, by default executes :NONAME part
1292 CODE CR \ replaced by this CODE definition
1301 \ ==============================================================================
1303 \ ==============================================================================
1305 \ From: John Hayes S1I
1306 \ Subject: tester.fr
1307 \ Date: Mon, 27 Nov 95 13:10:09 PST
1309 \ (C) 1995 JOHNS HOPKINS UNIVERSITY / APPLIED PHYSICS LABORATORY
1310 \ MAY BE DISTRIBUTED FREELY AS LONG AS THIS COPYRIGHT NOTICE REMAINS.
1313 \ 22/1/09 The words { and } have been changed to T{ and }T respectively to
1314 \ agree with the Forth 200X file ttester.fs. This avoids clashes with
1315 \ locals using { ... } and the FSL use of }
1318 \ 13/05/14 jmt. added colorised error messages.
1322 \ SET THE FOLLOWING FLAG TO TRUE FOR MORE VERBOSE OUTPUT; THIS MAY
1323 \ ALLOW YOU TO TELL WHICH TEST CAUSED YOUR SYSTEM TO HANG.
1328 \ : EMPTY-STACK ( ... -- ) \ EMPTY STACK: HANDLES UNDERFLOWED STACK TOO.
1330 \ IF DUP 0< IF NEGATE 0
1332 \ ELSE 0 DO DROP LOOP THEN
1335 \ : ERROR \ ( C-ADDR U -- ) DISPLAY AN ERROR MESSAGE FOLLOWED BY
1336 \ \ THE LINE THAT HAD THE ERROR.
1337 \ TYPE SOURCE TYPE CR \ DISPLAY LINE CORRESPONDING TO ERROR
1338 \ EMPTY-STACK \ THROW AWAY EVERY THING ELSE
1339 \ QUIT \ *** Uncomment this line to QUIT on an error
1342 VARIABLE ACTUAL-DEPTH \ STACK RECORD
1343 CREATE ACTUAL-RESULTS 20 CELLS ALLOT
1345 : T{ \ ( -- ) SYNTACTIC SUGAR.
1348 : -> \ ( ... -- ) RECORD DEPTH AND CONTENT OF STACK.
1349 DEPTH DUP ACTUAL-DEPTH ! \ RECORD DEPTH
1350 ?DUP IF \ IF THERE IS SOMETHING ON STACK
1351 0 DO ACTUAL-RESULTS I CELLS + ! LOOP \ SAVE THEM
1354 : }T \ ( ... -- ) COMPARE STACK (EXPECTED) CONTENTS WITH SAVED
1355 \ (ACTUAL) CONTENTS.
1356 DEPTH ACTUAL-DEPTH @ = IF \ IF DEPTHS MATCH
1357 DEPTH ?DUP IF \ IF THERE IS SOMETHING ON THE STACK
1358 0 DO \ FOR EACH STACK ITEM
1359 ACTUAL-RESULTS I CELLS + @ \ COMPARE ACTUAL WITH EXPECTED
1360 \ = 0= IF S" INCORRECT RESULT: " ERROR LEAVE THEN \ jmt
1361 = 0= IF TRUE ABORT" INCORRECT RESULT" THEN \ jmt : abort with colorised message
1364 ELSE \ DEPTH MISMATCH
1365 \ S" WRONG NUMBER OF RESULTS: " ERROR \ jmt
1366 TRUE ABORT" WRONG NUMBER OF RESULTS" \ jmt : abort with colorised message
1369 : TESTING \ ( -- ) TALKING COMMENT.
1371 IF DUP >R TYPE CR R> >IN !
1372 ELSE >IN ! DROP [CHAR] * EMIT
1375 \ Constant definitions
1379 0 INVERT CONSTANT 1SD
1380 1SD 1 RSHIFT CONSTANT MAX-INTD \ 01...1
1381 MAX-INTD INVERT CONSTANT MIN-INTD \ 10...0
1382 MAX-INTD 2/ CONSTANT HI-INT \ 001...1
1383 MIN-INTD 2/ CONSTANT LO-INT \ 110...1
1393 \ ==============================================================================
1395 \ ==============================================================================
1396 \ https://raw.githubusercontent.com/gerryjackson/forth2012-test-suite/master/src/doubletest.fth
1398 \ To test the ANS Forth Double-Number word set and double number extensions
1400 \ This program was written by Gerry Jackson in 2006, with contributions from
1401 \ others where indicated, and is in the public domain - it can be distributed
1402 \ and/or modified in any way but please retain this notice.
1404 \ This program is distributed in the hope that it will be useful,
1405 \ but WITHOUT ANY WARRANTY; without even the implied warranty of
1406 \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1408 \ The tests are not claimed to be comprehensive or correct
1409 \ ------------------------------------------------------------------------------
1410 \ Version 0.13 Assumptions and dependencies changed
1411 \ 0.12 1 August 2015 test D< acts on MS cells of double word
1412 \ 0.11 7 April 2015 2VALUE tested
1413 \ 0.6 1 April 2012 Tests placed in the public domain.
1414 \ Immediate 2CONSTANTs and 2VARIABLEs tested
1415 \ 0.5 20 November 2009 Various constants renamed to avoid
1416 \ redefinition warnings. <TRUE> and <FALSE> replaced
1417 \ with TRUE and FALSE
1418 \ 0.4 6 March 2009 { and } replaced with T{ and }T
1419 \ Tests rewritten to be independent of word size and
1421 \ 0.3 20 April 2007 ANS Forth words changed to upper case
1422 \ 0.2 30 Oct 2006 Updated following GForth test to include
1423 \ various constants from core.fr
1424 \ 0.1 Oct 2006 First version released
1425 \ ------------------------------------------------------------------------------
1426 \ The tests are based on John Hayes test program for the core word set
1428 \ Words tested in this file are:
1429 \ 2CONSTANT 2LITERAL 2VARIABLE D+ D- D. D.R D0< D0= D2* D2/
1430 \ D< D= D>S DABS DMAX DMIN DNEGATE M*/ M+ 2ROT DU<
1431 \ Also tests the interpreter and compiler reading a double number
1432 \ ------------------------------------------------------------------------------
1433 \ Assumptions and dependencies:
1434 \ - tester.fr (or ttester.fs), errorreport.fth and utilities.fth have been
1435 \ included prior to this file
1436 \ - the Core word set is available and tested
1437 ; ----------------------------------------------------------------------------
1438 TESTING interpreter and compiler reading double numbers, with/without prefixes
1442 T{ : RDL1 3. ; RDL1 -> 3 0 }T
1443 T{ : RDL2 -4. ; RDL2 -> -4 -1 }T
1446 DECIMAL BASE @ OLD-DBASE !
1447 T{ #12346789. -> 12346789. }T
1448 T{ #-12346789. -> -12346789. }T
1449 T{ $12aBcDeF. -> 313249263. }T
1450 T{ $-12AbCdEf. -> -313249263. }T
1451 T{ %10010110. -> 150. }T
1452 T{ %-10010110. -> -150. }T
1453 ; Check BASE is unchanged
1454 T{ BASE @ OLD-DBASE @ = -> TRUE }T
1456 ; Repeat in Hex mode
1457 16 OLD-DBASE ! 16 BASE !
1458 T{ #12346789. -> BC65A5. }T
1459 T{ #-12346789. -> -BC65A5. }T
1460 T{ $12aBcDeF. -> 12AbCdeF. }T
1461 T{ $-12AbCdEf. -> -12ABCDef. }T
1462 T{ %10010110. -> 96. }T
1463 T{ %-10010110. -> -96. }T
1464 ; Check BASE is unchanged
1465 T{ BASE @ OLD-DBASE @ = -> TRUE }T \ 2
1468 ; Check number prefixes in compile mode
1469 T{ : dnmp #8327. $-2cbe. %011010111. ; dnmp -> 8327. -11454. 215. }T
1471 ; ----------------------------------------------------------------------------
1474 T{ 1 2 2CONSTANT 2C1 -> }T
1476 T{ : CD1 2C1 ; -> }T
1478 T{ : CD2 2CONSTANT ; -> }T
1479 T{ -1 -2 CD2 2C2 -> }T
1481 T{ 4 5 2CONSTANT 2C3 IMMEDIATE 2C3 -> 4 5 }T
1482 T{ : CD6 2C3 2LITERAL ; CD6 -> 4 5 }T
1484 ; ----------------------------------------------------------------------------
1485 ; Some 2CONSTANTs for the following tests
1487 1SD MAX-INTD 2CONSTANT MAX-2INT \ 01...1
1488 0 MIN-INTD 2CONSTANT MIN-2INT \ 10...0
1489 MAX-2INT 2/ 2CONSTANT HI-2INT \ 001...1
1490 MIN-2INT 2/ 2CONSTANT LO-2INT \ 110...0
1492 ; ----------------------------------------------------------------------------
1495 T{ 0. DNEGATE -> 0. }T
1496 T{ 1. DNEGATE -> -1. }T
1497 T{ -1. DNEGATE -> 1. }T
1498 T{ MAX-2INT DNEGATE -> MIN-2INT SWAP 1+ SWAP }T
1499 T{ MIN-2INT SWAP 1+ SWAP DNEGATE -> MAX-2INT }T
1501 ; ----------------------------------------------------------------------------
1502 TESTING D+ with small integers
1504 T{ 0. 5. D+ -> 5. }T
1505 T{ -5. 0. D+ -> -5. }T
1506 T{ 1. 2. D+ -> 3. }T
1507 T{ 1. -2. D+ -> -1. }T
1508 T{ -1. 2. D+ -> 1. }T
1509 T{ -1. -2. D+ -> -3. }T
1510 T{ -1. 1. D+ -> 0. }T
1512 TESTING D+ with mid range integers
1514 T{ 0 0 0 5 D+ -> 0 5 }T
1515 T{ -1 5 0 0 D+ -> -1 5 }T
1516 T{ 0 0 0 -5 D+ -> 0 -5 }T
1517 T{ 0 -5 -1 0 D+ -> -1 -5 }T
1518 T{ 0 1 0 2 D+ -> 0 3 }T
1519 T{ -1 1 0 -2 D+ -> -1 -1 }T
1520 T{ 0 -1 0 2 D+ -> 0 1 }T
1521 T{ 0 -1 -1 -2 D+ -> -1 -3 }T
1522 T{ -1 -1 0 1 D+ -> -1 0 }T
1523 T{ MIN-INTD 0 2DUP D+ -> 0 1 }T
1524 T{ MIN-INTD S>D MIN-INTD 0 D+ -> 0 0 }T
1526 TESTING D+ with large double integers
1528 T{ HI-2INT 1. D+ -> 0 HI-INT 1+ }T
1529 T{ HI-2INT 2DUP D+ -> 1SD 1- MAX-INTD }T
1530 T{ MAX-2INT MIN-2INT D+ -> -1. }T
1531 T{ MAX-2INT LO-2INT D+ -> HI-2INT }T
1532 T{ HI-2INT MIN-2INT D+ 1. D+ -> LO-2INT }T
1533 T{ LO-2INT 2DUP D+ -> MIN-2INT }T
1535 ; ----------------------------------------------------------------------------
1536 TESTING D- with small integers
1538 T{ 0. 5. D- -> -5. }T
1539 T{ 5. 0. D- -> 5. }T
1540 T{ 0. -5. D- -> 5. }T
1541 T{ 1. 2. D- -> -1. }T
1542 T{ 1. -2. D- -> 3. }T
1543 T{ -1. 2. D- -> -3. }T
1544 T{ -1. -2. D- -> 1. }T
1545 T{ -1. -1. D- -> 0. }T
1547 TESTING D- with mid-range integers
1549 T{ 0 0 0 5 D- -> 0 -5 }T
1550 T{ -1 5 0 0 D- -> -1 5 }T
1551 T{ 0 0 -1 -5 D- -> 1 4 }T
1552 T{ 0 -5 0 0 D- -> 0 -5 }T
1553 T{ -1 1 0 2 D- -> -1 -1 }T
1554 T{ 0 1 -1 -2 D- -> 1 2 }T
1555 T{ 0 -1 0 2 D- -> 0 -3 }T
1556 T{ 0 -1 0 -2 D- -> 0 1 }T
1557 T{ 0 0 0 1 D- -> 0 -1 }T
1558 T{ MIN-INTD 0 2DUP D- -> 0. }T
1559 T{ MIN-INTD S>D MAX-INTD 0 D- -> 1 1SD }T
1561 TESTING D- with large integers
1563 T{ MAX-2INT MAX-2INT D- -> 0. }T
1564 T{ MIN-2INT MIN-2INT D- -> 0. }T
1565 T{ MAX-2INT HI-2INT D- -> LO-2INT DNEGATE }T
1566 T{ HI-2INT LO-2INT D- -> MAX-2INT }T
1567 T{ LO-2INT HI-2INT D- -> MIN-2INT 1. D+ }T
1568 T{ MIN-2INT MIN-2INT D- -> 0. }T
1569 T{ MIN-2INT LO-2INT D- -> LO-2INT }T
1571 ; ----------------------------------------------------------------------------
1574 T{ 0. D0< -> FALSE }T
1575 T{ 1. D0< -> FALSE }T
1576 T{ MIN-INTD 0 D0< -> FALSE }T
1577 T{ 0 MAX-INTD D0< -> FALSE }T
1578 T{ MAX-2INT D0< -> FALSE }T
1579 T{ -1. D0< -> TRUE }T
1580 T{ MIN-2INT D0< -> TRUE }T
1582 T{ 1. D0= -> FALSE }T
1583 T{ MIN-INTD 0 D0= -> FALSE }T
1584 T{ MAX-2INT D0= -> FALSE }T
1585 T{ -1 MAX-INTD D0= -> FALSE }T
1586 T{ 0. D0= -> TRUE }T
1587 T{ -1. D0= -> FALSE }T
1588 T{ 0 MIN-INTD D0= -> FALSE }T
1590 ; ----------------------------------------------------------------------------
1593 T{ 0. D2* -> 0. D2* }T
1594 T{ MIN-INTD 0 D2* -> 0 1 }T
1595 T{ HI-2INT D2* -> MAX-2INT 1. D- }T
1596 T{ LO-2INT D2* -> MIN-2INT }T
1600 T{ 0 1 D2/ -> MIN-INTD 0 }T
1601 T{ MAX-2INT D2/ -> HI-2INT }T
1602 T{ -1. D2/ -> -1. }T
1603 T{ MIN-2INT D2/ -> LO-2INT }T
1605 ; ----------------------------------------------------------------------------
1608 T{ 0. 1. D< -> TRUE }T
1609 T{ 0. 0. D< -> FALSE }T
1610 T{ 1. 0. D< -> FALSE }T
1611 T{ -1. 1. D< -> TRUE }T
1612 T{ -1. 0. D< -> TRUE }T
1613 T{ -2. -1. D< -> TRUE }T
1614 T{ -1. -2. D< -> FALSE }T
1615 T{ 0 1 1. D< -> FALSE }T \ Suggested by Helmut Eller
1616 T{ 1. 0 1 D< -> TRUE }T
1617 T{ 0 -1 1 -2 D< -> FALSE }T
1618 T{ 1 -2 0 -1 D< -> TRUE }T
1619 T{ -1. MAX-2INT D< -> TRUE }T
1620 T{ MIN-2INT MAX-2INT D< -> TRUE }T
1621 T{ MAX-2INT -1. D< -> FALSE }T
1622 T{ MAX-2INT MIN-2INT D< -> FALSE }T
1623 T{ MAX-2INT 2DUP -1. D+ D< -> FALSE }T
1624 T{ MIN-2INT 2DUP 1. D+ D< -> TRUE }T
1625 T{ MAX-INTD S>D 2DUP 1. D+ D< -> TRUE }T \ Ensure D< acts on MS cells
1627 T{ -1. -1. D= -> TRUE }T
1628 T{ -1. 0. D= -> FALSE }T
1629 T{ -1. 1. D= -> FALSE }T
1630 T{ 0. -1. D= -> FALSE }T
1631 T{ 0. 0. D= -> TRUE }T
1632 T{ 0. 1. D= -> FALSE }T
1633 T{ 1. -1. D= -> FALSE }T
1634 T{ 1. 0. D= -> FALSE }T
1635 T{ 1. 1. D= -> TRUE }T
1637 T{ 0 -1 0 -1 D= -> TRUE }T
1638 T{ 0 -1 0 0 D= -> FALSE }T
1639 T{ 0 -1 0 1 D= -> FALSE }T
1640 T{ 0 0 0 -1 D= -> FALSE }T
1641 T{ 0 0 0 0 D= -> TRUE }T
1642 T{ 0 0 0 1 D= -> FALSE }T
1643 T{ 0 1 0 -1 D= -> FALSE }T
1644 T{ 0 1 0 0 D= -> FALSE }T
1645 T{ 0 1 0 1 D= -> TRUE }T
1647 T{ MAX-2INT MIN-2INT D= -> FALSE }T
1648 T{ MAX-2INT 0. D= -> FALSE }T
1649 T{ MAX-2INT MAX-2INT D= -> TRUE }T
1650 T{ MAX-2INT HI-2INT D= -> FALSE }T
1651 T{ MAX-2INT MIN-2INT D= -> FALSE }T
1652 T{ MIN-2INT MIN-2INT D= -> TRUE }T
1653 T{ MIN-2INT LO-2INT D= -> FALSE }T
1654 T{ MIN-2INT MAX-2INT D= -> FALSE }T
1656 ; ----------------------------------------------------------------------------
1657 TESTING 2LITERAL 2VARIABLE
1659 T{ : CD3 [ MAX-2INT ] 2LITERAL ; -> }T
1660 T{ CD3 -> MAX-2INT }T
1661 T{ 2VARIABLE 2V1 -> }T
1664 T{ -1 -2 2V1 2! -> }T
1665 T{ 2V1 2@ -> -1 -2 }T
1666 T{ : CD4 2VARIABLE ; -> }T
1668 T{ : CD5 2V2 2! ; -> }T
1670 T{ 2V2 2@ -> -2 -1 }T
1671 T{ 2VARIABLE 2V3 IMMEDIATE 5 6 2V3 2! -> }T
1673 T{ : CD7 2V3 [ 2@ ] 2LITERAL ; CD7 -> 5 6 }T
1674 T{ : CD8 [ 6 7 ] 2V3 [ 2! ] ; 2V3 2@ -> 6 7 }T
1676 ; ----------------------------------------------------------------------------
1679 T{ 1. 2. DMAX -> 2. }T
1680 T{ 1. 0. DMAX -> 1. }T
1681 T{ 1. -1. DMAX -> 1. }T
1682 T{ 1. 1. DMAX -> 1. }T
1683 T{ 0. 1. DMAX -> 1. }T
1684 T{ 0. -1. DMAX -> 0. }T
1685 T{ -1. 1. DMAX -> 1. }T
1686 T{ -1. -2. DMAX -> -1. }T
1688 T{ MAX-2INT HI-2INT DMAX -> MAX-2INT }T
1689 T{ MAX-2INT MIN-2INT DMAX -> MAX-2INT }T
1690 T{ MIN-2INT MAX-2INT DMAX -> MAX-2INT }T
1691 T{ MIN-2INT LO-2INT DMAX -> LO-2INT }T
1693 T{ MAX-2INT 1. DMAX -> MAX-2INT }T
1694 T{ MAX-2INT -1. DMAX -> MAX-2INT }T
1695 T{ MIN-2INT 1. DMAX -> 1. }T
1696 T{ MIN-2INT -1. DMAX -> -1. }T
1699 T{ 1. 2. DMIN -> 1. }T
1700 T{ 1. 0. DMIN -> 0. }T
1701 T{ 1. -1. DMIN -> -1. }T
1702 T{ 1. 1. DMIN -> 1. }T
1703 T{ 0. 1. DMIN -> 0. }T
1704 T{ 0. -1. DMIN -> -1. }T
1705 T{ -1. 1. DMIN -> -1. }T
1706 T{ -1. -2. DMIN -> -2. }T
1708 T{ MAX-2INT HI-2INT DMIN -> HI-2INT }T
1709 T{ MAX-2INT MIN-2INT DMIN -> MIN-2INT }T
1710 T{ MIN-2INT MAX-2INT DMIN -> MIN-2INT }T
1711 T{ MIN-2INT LO-2INT DMIN -> MIN-2INT }T
1713 T{ MAX-2INT 1. DMIN -> 1. }T
1714 T{ MAX-2INT -1. DMIN -> -1. }T
1715 T{ MIN-2INT 1. DMIN -> MIN-2INT }T
1716 T{ MIN-2INT -1. DMIN -> MIN-2INT }T
1718 ; ----------------------------------------------------------------------------
1721 T{ 1234 0 D>S -> 1234 }T
1722 T{ -1234 -1 D>S -> -1234 }T
1723 T{ MAX-INTD 0 D>S -> MAX-INTD }T
1724 T{ MIN-INTD -1 D>S -> MIN-INTD }T
1727 T{ -1. DABS -> 1. }T
1728 T{ MAX-2INT DABS -> MAX-2INT }T
1729 T{ MIN-2INT 1. D+ DABS -> MAX-2INT }T
1731 ; ----------------------------------------------------------------------------
1734 T{ HI-2INT 1 M+ -> HI-2INT 1. D+ }T
1735 T{ MAX-2INT -1 M+ -> MAX-2INT -1. D+ }T
1736 T{ MIN-2INT 1 M+ -> MIN-2INT 1. D+ }T
1737 T{ LO-2INT -1 M+ -> LO-2INT -1. D+ }T
1739 ; To correct the result if the division is floored, only used when
1740 ; necessary i.e. negative quotient and remainder <> 0
1742 : ?FLOORED [ -3 2 / -2 = ] LITERAL IF 1. D- THEN ;
1744 T{ 5. 7 11 M*/ -> 3. }T
1745 T{ 5. -7 11 M*/ -> -3. ?FLOORED }T \ FLOORED -4.
1746 T{ -5. 7 11 M*/ -> -3. ?FLOORED }T \ FLOORED -4.
1747 T{ -5. -7 11 M*/ -> 3. }T
1748 T{ MAX-2INT 8 16 M*/ -> HI-2INT }T
1749 T{ MAX-2INT -8 16 M*/ -> HI-2INT DNEGATE ?FLOORED }T \ FLOORED SUBTRACT 1
1750 T{ MIN-2INT 8 16 M*/ -> LO-2INT }T
1751 T{ MIN-2INT -8 16 M*/ -> LO-2INT DNEGATE }T
1752 T{ MAX-2INT MAX-INTD MAX-INTD M*/ -> MAX-2INT }T
1753 T{ MAX-2INT MAX-INTD 2/ MAX-INTD M*/ -> MAX-INTD 1- HI-2INT NIP }T
1754 T{ MIN-2INT LO-2INT NIP 1+ DUP 1- NEGATE M*/ -> 0 MAX-INTD 1- }T
1755 T{ MIN-2INT LO-2INT NIP 1- MAX-INTD M*/ -> MIN-INTD 3 + HI-2INT NIP 2 + }T
1756 T{ MAX-2INT LO-2INT NIP DUP NEGATE M*/ -> MAX-2INT DNEGATE }T
1757 T{ MIN-2INT MAX-INTD DUP M*/ -> MIN-2INT }T
1759 ; ----------------------------------------------------------------------------
1762 ; Create some large double numbers
1763 MAX-2INT 71 73 M*/ 2CONSTANT DBL1
1764 MIN-2INT 73 79 M*/ 2CONSTANT DBL2
1766 : D>ASCII ( D -- CADDR U )
1767 DUP >R <# DABS #S R> SIGN #> ( -- CADDR1 U )
1768 HERE SWAP 2DUP 2>R CHARS DUP ALLOT MOVE 2R>
1771 DBL1 D>ASCII 2CONSTANT "DBL1"
1772 DBL2 D>ASCII 2CONSTANT "DBL2"
1775 CR ." You should see lines duplicated:" CR
1776 5 SPACES "DBL1" TYPE CR
1778 8 SPACES "DBL1" DUP >R TYPE CR
1779 5 SPACES DBL1 R> 3 + D.R CR
1780 5 SPACES "DBL2" TYPE CR
1782 10 SPACES "DBL2" DUP >R TYPE CR
1783 5 SPACES DBL2 R> 5 + D.R CR
1786 T{ DOUBLEOUTPUT -> }T
1787 ; ----------------------------------------------------------------------------
1788 TESTING 2ROT DU< (Double Number extension words)
1790 T{ 1. 2. 3. 2ROT -> 2. 3. 1. }T
1791 T{ MAX-2INT MIN-2INT 1. 2ROT -> MIN-2INT 1. MAX-2INT }T
1793 T{ 1. 1. DU< -> FALSE }T
1794 T{ 1. -1. DU< -> TRUE }T
1795 T{ -1. 1. DU< -> FALSE }T
1796 T{ -1. -2. DU< -> FALSE }T
1797 T{ 0 1 1. DU< -> FALSE }T
1798 T{ 1. 0 1 DU< -> TRUE }T
1799 T{ 0 -1 1 -2 DU< -> FALSE }T
1800 T{ 1 -2 0 -1 DU< -> TRUE }T
1802 T{ MAX-2INT HI-2INT DU< -> FALSE }T
1803 T{ HI-2INT MAX-2INT DU< -> TRUE }T
1804 T{ MAX-2INT MIN-2INT DU< -> TRUE }T
1805 T{ MIN-2INT MAX-2INT DU< -> FALSE }T
1806 T{ MIN-2INT LO-2INT DU< -> TRUE }T
1808 ; ----------------------------------------------------------------------------
1811 T{ 1111 2222 2VALUE 2VAL -> }T
1812 T{ 2VAL -> 1111 2222 }T
1813 T{ 3333 4444 TO 2VAL -> }T
1814 T{ 2VAL -> 3333 4444 }T
1815 T{ : TO-2VAL TO 2VAL ; 5555 6666 TO-2VAL -> }T
1816 T{ 2VAL -> 5555 6666 }T
1818 CR .( End of Double-Number word tests) CR