1 \ -*- coding: utf-8 -*-
3 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
4 \ MSP_EXP430FR4133 MSP_EXP430FR2433 MSP_EXP430FR2355 CHIPSTICK_FR2433
5 \ MY_MSP430FR5738_1 MY_MSP430FR5738 MY_MSP430FR5948 MY_MSP430FR5948_1
9 \ Fast Forth For Texas Instrument MSP430FRxxxx FRAM devices
10 \ Copyright (C) <2015> <J.M. THOORENS>
12 \ This program is free software: you can redistribute it and/or modify
13 \ it under the terms of the GNU General Public License as published by
14 \ the Free Software Foundation, either version 3 of the License, or
15 \ (at your option) any later version.
17 \ This program is distributed in the hope that it will be useful,
18 \ but WITHOUT ANY WARRANTY; without even the implied warranty of
19 \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 \ GNU General Public License for more details.
22 \ You should have received a copy of the GNU General Public License
23 \ along with this program. If not, see <http://www.gnu.org/licenses/>.
26 \ rDODOES to rEXIT must be saved before use and restored after
27 \ scratch registers Y to S are free for use
28 \ under interrupt, IP is free for use
30 \ FORTH conditionnals: unary{ 0= 0< 0> }, binary{ = < > U< }
32 \ ASSEMBLER conditionnal usage with IF UNTIL WHILE S< S>= U< U>= 0= 0<> 0>=
34 \ ASSEMBLER conditionnal usage with ?JMP ?GOTO S< S>= U< U>= 0= 0<> <0
37 \ https://forth-standard.org/standard/double/DtoS
38 \ D>S d -- n double prec -> single.
45 [UNDEFINED] {ANS_COMP} [IF]
46 \ https://forth-standard.org/standard/core/StoD
47 \ S>D n -- d single -> double prec.
53 \ https://forth-standard.org/standard/core/TwoFetch
54 \ 2@ a-addr -- x1 x2 fetch 2 cells ; the lower address will appear on top of stack
63 \ https://forth-standard.org/standard/core/TwoDUP
64 \ 2DUP x1 x2 -- x1 x2 x1 x2 dup top 2 cells
66 SUB #4,PSP \ -- x1 x x x2
67 MOV TOS,2(PSP) \ -- x1 x2 x x2
68 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x2
73 \ https://forth-standard.org/standard/core/TwoDROP
74 \ 2DROP x1 x2 -- drop 2 cells
82 \ https://forth-standard.org/standard/core/TwoSWAP
83 \ 2SWAP x1 x2 x3 x4 -- x3 x4 x1 x2
85 MOV @PSP,W \ -- x1 x2 x3 x4 W=x3
86 MOV 4(PSP),0(PSP) \ -- x1 x2 x1 x4
87 MOV W,4(PSP) \ -- x3 x2 x1 x4
88 MOV TOS,W \ -- x3 x2 x1 x4 W=x4
89 MOV 2(PSP),TOS \ -- x3 x2 x1 x2 W=x4
90 MOV W,2(PSP) \ -- x3 x4 x1 x2
95 \ https://forth-standard.org/standard/core/TwoOVER
96 \ 2OVER x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2
98 SUB #4,PSP \ -- x1 x2 x3 x x x4
99 MOV TOS,2(PSP) \ -- x1 x2 x3 x4 x x4
100 MOV 8(PSP),0(PSP) \ -- x1 x2 x3 x4 x1 x4
101 MOV 6(PSP),TOS \ -- x1 x2 x3 x4 x1 x2
106 [THEN] \ undefined ANS_COMP
108 \ https://forth-standard.org/standard/double/TwoROT
109 \ Rotate the top three cell pairs on the stack bringing cell pair x1 x2 to the top of the stack.
113 MOV 4(PSP),8(PSP) \ 5
114 MOV 2(PSP),6(PSP) \ 5
156 \ https://forth-standard.org/standard/double/DEqual
158 CMP TOS,2(PSP) \ 3 ud1H - ud2H
161 CMP @PSP,4(PSP) \ 4 ud1L - ud2L
171 \ https://forth-standard.org/standard/double/Dless
172 \ flag is true if and only if d1 is less than d2
174 CMP TOS,2(PSP) \ 3 d1H - d2H
180 CMP @PSP,4(PSP) \ 4 d1L - d2L
191 CMP 2(PSP),TOS \ 3 d2H - d1H
197 CMP 4(PSP),0(PSP) \ 4 d2L - d1L
207 \ https://forth-standard.org/standard/double/DUless
208 \ flag is true if and only if ud1 is less than ud2
210 CMP TOS,2(PSP) \ 3 ud1H - ud2H
216 CMP @PSP,4(PSP) \ 4 ud1L - ud2L
251 \ https://forth-standard.org/standard/double/DTwoDiv
259 \ https://forth-standard.org/standard/double/DTwoTimes
268 2OVER 2OVER \ ( d1 d2 d1 d2 )
269 D> IF 2DROP ELSE 2NIP THEN
274 2OVER 2OVER \ ( d1 d2 d1 d2 )
275 D< IF 2DROP ELSE 2NIP THEN
287 $1A04 C@ $EF > [IF] ; test tag value MSP430FR413x subfamily without hardware_MPY
290 \ signed multiply 32*16 --> 48 / 16 = 32
291 CODE M*/ \ d1lo d1hi n1 +n2 -- d2lo d2hi
293 XOR @PSP,S \ S keep sign of M* result
294 BIT #$8000,2(PSP) \ MD < 0 ?
295 0<> IF XOR #-1,4(PSP)
305 \ PUSHM R5,R4 \ 6 save R5 ~ R4 regs
306 PUSHM #2,R5 \ 6 save R5,R4 regs
307 MOV 4(PSP),Y \ 3 MDlo
308 MOV 2(PSP),T \ 3 MDhi
309 MOV @PSP+,W \ 2 MRlo -- d1lo d1hi +n2
311 MOV #0,2(PSP) \ 3 RESlo=0
312 MOV #0,0(PSP) \ 3 REShi=0 -- p1lo p1hi +n2
313 MOV #0,R5 \ 1 RESLO=0
314 MOV #1,X \ 1 BIT TEST REGlo
315 BEGIN BIT X,W \ 1 test actual bit
316 0<> IF ADD Y,2(PSP) \ 3 IF 1: ADD MDlo TO RESlo
317 ADDC T,0(PSP) \ 3 ADDC MDhi TO REShi
318 ADDC R4,R5 \ 1 ADDC MDLO TO RESLO
319 THEN ADD Y,Y \ 1 (RLA LSBs) MDlo *2
320 ADDC T,T \ 1 (RLC MSBs) MDhi *2
321 ADDC R4,R4 \ 1 (RLA LSBs) MDLO *2
322 ADD X,X \ 1 (RLA) NEXT BIT TO TEST
323 U>= UNTIL MOV R5,W \ 1 IF BIT IN CARRY: FINISHED 32 * 16~ (average loop)
324 \ POPM R4,R5 \ 6 restore R4 ~ R5 regs
325 POPM #2,R5 \ 6 restore R4 R5 regs
329 AND #-1,S \ clear V, set N, test M* sign
339 ADD #10,X \ 2 X = MUSMOD2 addr
341 MOV @PSP+,0(PSP) \ rem d2lo d2hi -- d2lo d2hi
347 CODE M*/ \ d1 * n1 / +n2 -- d2
348 MOV 4(PSP),&MPYS32L \ 5 Load 1st operand
349 MOV 2(PSP),&MPYS32H \ 5
350 MOV @PSP+,&OP2 \ 4 load 2nd operand
352 ADD #10,X \ 2 X = MUSMOD2 addr
353 MOV TOS,T \ 1 T = DIVlo
354 MOV &RES0,S \ 3 S = DVDlo
355 MOV &RES1,TOS \ 3 TOS = DVDhi
356 MOV &RES2,W \ 3 W = REMlo
358 MOV @PSP+,0(PSP) \ rem dquot -- d2
365 \ https://forth-standard.org/standard/double/TwoVARIABLE
372 [UNDEFINED] 2CONSTANT [IF]
373 \ https://forth-standard.org/standard/core/TwoFetch
374 \ 2@ a-addr -- x1 x2 fetch 2 cells ; the lower address will appear on top of stack
383 \ https://forth-standard.org/standard/double/TwoCONSTANT
384 : 2CONSTANT \ udlo/dlo/Flo udhi/dhi/Shi -- to create double or s15q16 CONSTANT
386 , , \ compile Shi then Flo
406 : ?floored [ -3 2 / -2 = ] LITERAL IF 1. D- THEN ;
408 5. 7 11 M*/ D. ; 3 -->
409 5. -7 11 M*/ ?floored D. ; -3 -->
410 -5. 7 11 M*/ ?floored D. ; -3 -->
411 -5. -7 11 M*/ D. ; 3 -->
412 $7FFFFFFF. 8 16 M*/ D. ; $7FFF -->