OSDN Git Service

V205
[fast-forth/master.git] / ADDON / ANS_COMPLEMENT.asm
1 ; -*- coding: utf-8 -*-
2 ; http://patorjk.com/software/taag/#p=display&f=Banner&t=Fast Forth
3
4 ; Fast Forth For Texas Instrument MSP430FRxxxx FRAM devices
5 ; Copyright (C) <2015>  <J.M. THOORENS>
6 ;
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.
11 ;
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.
16 ;
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/>.
19
20
21     FORTHWORD "{ANS_COMP}"
22     mNEXT
23
24     .IFNDEF ARITHMETIC
25     .include "ADDON/ARITHMETIC.asm"
26     .ENDIF
27     .IFNDEF ALIGNMENT
28     .include "ADDON/ALIGNMENT.asm"
29     .ENDIF
30     .IFNDEF PORTABILITY
31     .include "ADDON/PORTABILITY.asm"
32     .ENDIF
33     .IFNDEF DOUBLE
34     .include "ADDON/DOUBLE.asm"
35     .ENDIF
36
37 ;https://forth-standard.org/standard/core/AND
38 ;C AND    x1 x2 -- x3           logical AND
39             FORTHWORD "AND"
40 ANDD        AND     @PSP+,TOS
41             mNEXT
42
43 ;https://forth-standard.org/standard/core/OR
44 ;C OR     x1 x2 -- x3           logical OR
45             FORTHWORD "OR"
46 ORR         BIS     @PSP+,TOS
47             mNEXT
48
49 ;https://forth-standard.org/standard/core/XOR
50 ;C XOR    x1 x2 -- x3           logical XOR
51             FORTHWORD "XOR"
52 XORR        XOR     @PSP+,TOS
53             mNEXT
54
55 ;https://forth-standard.org/standard/core/INVERT
56 ;C INVERT   x1 -- x2            bitwise inversion
57             FORTHWORD "INVERT"
58 INVERT      XOR     #-1,TOS
59             mNEXT
60
61 ;https://forth-standard.org/standard/core/LSHIFT
62 ;C LSHIFT  x1 u -- x2    logical L shift u places
63             FORTHWORD "LSHIFT"
64 LSHIFT      MOV     @PSP+,W
65             AND     #1Fh,TOS        ; no need to shift more than 16
66             JZ      LSH_X
67 LSH_1:      ADD     W,W
68             SUB     #1,TOS
69             JNZ     LSH_1
70 LSH_X:      MOV     W,TOS
71             mNEXT
72
73 ;https://forth-standard.org/standard/core/RSHIFT
74 ;C RSHIFT  x1 u -- x2    logical R shift u places
75             FORTHWORD "RSHIFT"
76 RSHIFT      MOV     @PSP+,W
77             AND     #1Fh,TOS        ; no need to shift more than 16
78             JZ      RSH_X
79 RSH_1:      BIC     #1,SR           ; CLRC
80             RRC     W
81             SUB     #1,TOS
82             JNZ     RSH_1
83 RSH_X:      MOV     W,TOS
84             mNEXT
85
86 ;https://forth-standard.org/standard/core/TwoTimes
87 ;C 2*      x1 -- x2         arithmetic left shift
88             FORTHWORD "2*"
89 TWOTIMES    ADD     TOS,TOS
90             mNEXT
91
92 ;https://forth-standard.org/standard/core/TwoDiv
93 ;C 2/      x1 -- x2        arithmetic right shift
94             FORTHWORD "2/"
95 TWODIV      RRA     TOS
96             mNEXT
97
98 ;https://forth-standard.org/standard/core/MAX
99 ;C MAX    n1 n2 -- n3       signed maximum
100             FORTHWORD "MAX"
101 MAX:        CMP     @PSP,TOS    ; n2-n1
102             JL      SELn1       ; n2<n1
103 SELn2:      ADD     #2,PSP
104             mNEXT
105
106 ;https://forth-standard.org/standard/core/MIN
107 ;C MIN    n1 n2 -- n3       signed minimum
108             FORTHWORD "MIN"
109 MIN:        CMP     @PSP,TOS    ; n2-n1
110             JL      SELn2       ; n2<n1
111 SELn1:      MOV     @PSP+,TOS
112             mNEXT
113
114 ;https://forth-standard.org/standard/core/PlusStore
115 ;C +!     n/u a-addr --       add to memory
116             FORTHWORD "+!"
117 PLUSSTORE   ADD     @PSP+,0(TOS)
118             MOV     @PSP+,TOS
119             mNEXT
120
121 ;https://forth-standard.org/standard/core/CHAR
122 ;C CHAR   -- char           parse ASCII character
123             FORTHWORD "CHAR"
124 CHARR       mDOCOL
125             .word   FBLANK,WORDD,ONEPLUS,CFETCH,EXIT
126
127 ;https://forth-standard.org/standard/core/BracketCHAR
128 ;C [CHAR]   --          compile character literal
129             FORTHWORDIMM "[CHAR]"        ; immediate
130 BRACCHAR    mDOCOL
131             .word   CHARR
132             .word   lit,lit,COMMA
133             .word   COMMA,EXIT
134
135 ;https://forth-standard.org/standard/core/FILL
136 ;C FILL   c-addr u char --  fill memory with char
137             FORTHWORD "FILL"
138 FILL        MOV     @PSP+,X     ; count
139             MOV     @PSP+,W     ; address
140             CMP     #0,X
141             JZ      FILL_X
142 FILL_1:     MOV.B   TOS,0(W)    ; store char in memory
143             ADD     #1,W
144             SUB     #1,X
145             JNZ     FILL_1
146 FILL_X:     MOV     @PSP+,TOS   ; pop new TOS
147             mNEXT
148
149 ;https://forth-standard.org/standard/core/HEX
150             FORTHWORD "HEX"
151 HEX         MOV     #16,&BASE
152             mNEXT
153
154 ;https://forth-standard.org/standard/core/DECIMAL
155             FORTHWORD "DECIMAL"
156 DECIMAL     MOV     #10,&BASE
157             mNEXT
158
159 ;https://forth-standard.org/standard/core/p
160 ;C (                \  --     paren ; skip input until )
161             FORTHWORDIMM "\40"      ; immediate
162 PARENT       mDOCOL
163             .word   lit,')',WORDD,DROP,EXIT
164
165 ;https://forth-standard.org/standard/core/Dotp
166 ; .(                \  --     dotparen ; type comment immediatly.
167             FORTHWORDIMM ".\40"        ; immediate
168 DOTPAREN    mDOCOL
169
170     .IFDEF LOWERCASE
171             .word   CAPS_OFF
172             .word   lit,')',WORDD
173             .word   CAPS_ON
174             .word   COUNT,TYPE
175             .word   EXIT
176     .ELSE
177
178             .word   lit,')',WORDD
179             .word   COUNT,TYPE
180             .word   EXIT
181     .ENDIF ; LOWERCASE
182
183 ;https://forth-standard.org/standard/core/SOURCE
184 ;C SOURCE   -- adr u    current input buffer
185             FORTHWORD "SOURCE"
186             SUB     #4,PSP
187             MOV     TOS,2(PSP)
188             MOV     &SOURCE_LEN,TOS
189             MOV     &SOURCE_ADR,0(PSP)
190             mNEXT
191
192 ;https://forth-standard.org/standard/core/toBODY
193 ; >BODY     -- PFA      leave PFA of created word
194             FORTHWORD ">BODY"
195             ADD     #4,TOS
196             mNEXT
197
198
199 ;https://forth-standard.org/standard/core/toIN
200 ;C >IN     -- a-addr       holds offset in input stream
201             FORTHWORD ">IN"
202 FTOIN       mDOCON
203             .word   TOIN    ; VARIABLE address in RAM space
204
205
206     .IFNDEF PAD
207 ;https://forth-standard.org/standard/core/PAD
208 ; PAD           --  pad address
209             FORTHWORD "PAD"
210 PAD         mDOCON
211             .WORD    PAD_ORG
212
213     .ENDIF