1 ; -*- coding: utf-8 -*-
2 ; http://patorjk.com/software/taag/#p=display&f=Banner&t=Fast Forth
4 ; Fast Forth For Texas Instrument MSP430FRxxxx FRAM devices
5 ; Copyright (C) <2015> <J.M. THOORENS>
7 ; This program is free software: you can redistribute it and/or modify
8 ; it under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation, either version 3 of the License, or
10 ; (at your option) any later version.
12 ; This program is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ; GNU General Public License for more details.
17 ; You should have received a copy of the GNU General Public License
18 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ;https://forth-standard.org/standard/core/StoD
26 ;C S>D n -- d single -> double prec.
34 ;https://forth-standard.org/standard/core/UMTimes
35 ;C UM* u1 u2 -- ud unsigned 16x16->32 mult.
37 UMSTAR MOV @PSP,&MPY ; Load 1st operand
38 MOV TOS,&OP2 ; Load 2nd operand
39 MOV &RES0,0(PSP) ; low result on stack
40 MOV &RES1,TOS ; high result in TOS
43 ;https://forth-standard.org/standard/core/MTimes
44 ;C M* n1 n2 -- dlo dhi signed 16*16->32 multiply
54 ;https://forth-standard.org/standard/core/MTimes
55 ;C M* n1 n2 -- dlo dhi signed 16*16->32 multiply
57 MSTAR: MOV TOS,S ; TOS= n2
58 XOR @PSP,S ; S contains sign of result
59 CMP #0,0(PSP) ; n1 > -1 ?
61 XOR #-1,0(PSP) ; no : n1 --> u1
63 u1n2MSTAR CMP #0,TOS ; n2 <= -1 ?
65 XOR #-1,TOS ; y: n2 --> u2
67 u1u2MSTAR .word 151Dh ; PUSHM IP,S (1+1 push,IP=0Dh)
69 .word UMSTAR ; UMSTAR use S,T,W,X,Y
71 .word 171Ch ; POPM S,IP (1+1 pop,S=0Ch)
72 CMP #0,S ; result > -1 ?
74 XOR #-1,0(PSP) ; no : ud --> d
82 ;https://forth-standard.org/standard/core/SMDivREM
83 ;C SM/REM d1lo d1hi n2 -- n3 n4 symmetric signed div
85 SMSLASHREM MOV TOS,S ;1 S=divisor
86 MOV @PSP,T ;2 T=rem_sign
87 CMP #0,TOS ;1 n2 >= 0 ?
88 JGE d1u2SMSLASHREM ;2 yes
91 d1u2SMSLASHREM ; -- d1 u2
92 CMP #0,0(PSP) ;3 d1hi >= 0 ?
93 JGE ud1u2SMSLASHREM ;2 yes
94 XOR #-1,2(PSP) ;4 d1lo
95 XOR #-1,0(PSP) ;4 d1hi
96 ADD #1,2(PSP) ;4 d1lo+1
97 ADDC #0,0(PSP) ;4 d1hi+C
98 ud1u2SMSLASHREM ; -- ud1 u2
99 .word 151Ch ;4 PUSHM S,T (1+1 push,S=0Ch)
102 .word 171Bh ;4 POPM T,S (1+1 pop,T=0Bh)
103 CMP #0,T ;1 -- ur uq T=rem_sign>=0?
104 JGE SMSLASHREMnruq ;2 yes
108 XOR S,T ;1 S=divisor T=quot_sign
109 CMP #0,T ;1 -- nr uq T=quot_sign>=0?
110 JGE SMSLASHREMnrnq ;2 yes
113 SMSLASHREMnrnq ; -- nr nq S=divisor
116 ;https://forth-standard.org/standard/core/FMDivMOD
117 ;C FM/MOD d1 n1 -- r q floored signed div'n
122 FMSLASHMOD1 FORTHtoASM ; -- remainder quotient S=divisor
125 CMP #1,TOS ; quotient < 1 ?
127 QUOTLESSONE ADD S,0(PSP) ; add divisor to remainder
128 SUB #1,TOS ; decrement quotient
133 ;https://forth-standard.org/standard/core/NEGATE
134 ;C NEGATE x1 -- x2 two's complement
138 ;https://forth-standard.org/standard/core/ABS
139 ;C ABS n1 -- +n2 absolute value
145 ;https://forth-standard.org/standard/core/Times
146 ;C * n1 n2 -- n3 signed multiply
149 .word MSTAR,DROP,EXIT
151 ;https://forth-standard.org/standard/core/DivMOD
152 ;C /MOD n1 n2 -- n3 n4 signed divide/rem'dr
155 .word TOR,STOD,RFROM,FMSLASHMOD,EXIT
157 ;https://forth-standard.org/standard/core/Div
158 ;C / n1 n2 -- n3 signed divide
161 .word TOR,STOD,RFROM,FMSLASHMOD,NIP,EXIT
163 ;https://forth-standard.org/standard/core/MOD
164 ;C MOD n1 n2 -- n3 signed remainder
167 .word TOR,STOD,RFROM,FMSLASHMOD,DROP,EXIT
169 ;https://forth-standard.org/standard/core/TimesDivMOD
170 ;C */MOD n1 n2 n3 -- n4 n5 n1*n2/n3, rem"
173 .word TOR,MSTAR,RFROM,FMSLASHMOD,EXIT
175 ;https://forth-standard.org/standard/core/TimesDiv
176 ;C */ n1 n2 n3 -- n4 n1*n2/n3
179 .word TOR,MSTAR,RFROM,FMSLASHMOD,NIP,EXIT