File: prim.fs

package info (click to toggle)
gforth 0.7.3%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,888 kB
  • ctags: 1,977
  • sloc: ansic: 8,535; sh: 3,666; lisp: 1,778; makefile: 1,011; yacc: 186; sed: 141; lex: 102; awk: 21
file content (196 lines) | stat: -rw-r--r-- 3,893 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
\ Prims for ShBoom

\ Copyright (C) 1997,2003,2004,2007 Free Software Foundation, Inc.

\ This file is part of Gforth.

\ Gforth is free software; you can redistribute it and/or
\ modify it under the terms of the GNU General Public License
\ as published by the Free Software Foundation, either version 3
\ of the License, or (at your option) any later version.

\ This program is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
\ GNU General Public License for more details.

\ You should have received a copy of the GNU General Public License
\ along with this program. If not, see http://www.gnu.org/licenses/.

hex

\ Used Global Registers:
\
\ G0 used by DIV and MUL
\ G1 UP


6e ALIAS ;s
: add,    M c0 ;
: add_pc, _inline       M bb ;
: +       M e8 ;
: addc,   M c2 ;
: addexp, M d2 ;
: and     M e1 ;
: bkpt,   M 3c ;
: lcache, M 4d ;
: scache, M 45 ;
: execute M 4e ; 	\ call[]
: cmp,    M cb ;
: copyb,  M d0 ;
: 1-      M cf ;
: 4-      M cd ;
: cell-   M cd ;
: dec_ct, M c1 ;
: denorm, M c5 ;
: ldepth, M 9b ;
: sdepth, M 9f ;
: di,     M b7 ;
: divu,   M de ;
: ei,     M b6 ;
: 0=      M e5 ;        \ eqz
: expdif, M c4 ;
: extexp, M db ; 
: extsig, M dc ;
: lframe, M be ;
: sframe, M bf ;
: iand,   M e9 ;
: 1+      M ce ;
: 4+      M cc ;
: cell+   M cc ;
: char+   M ce ; 
: ld[--r0], M 44 ;
: ld[--x],  M 4a ;
: ld[r0++], M 46 ;
: ld[r0],   M 42 ;
: ld[x++],  M 49 ;
: ld[x],  M 41 ;
: @       M 40 ;
: c@      M 48 ;
: ldo[],  M 96 ;
: ldo.o[], M 97 ;
: mloop,  M 38 ;
: mloopc, M 39 ;
: mloopn, M 3a ;
: mloopnc, M 3d ; 
: mloopp, M 3e ;
: mloopnz, M 3f ;
: mloopz, M 3b ;
: mulfs,  M d6 ;
: muls,   M d5 ;
: mulu,   M d7 ;
: mxm,    M df ;
: negate  M c9 ;
: noop    M ea ;
: norml,  M c7 ;
: normr,  M c6 ;
: notc,   M dd ;
: or      M e0 ;
: drop    M b3 ;           \ pop
: pop_ct, M b4 ;
\ ,pop_gi !!
: pop_la, _inline M bd ;
: >r _inline M ba ;		\ pop_lstack
: pop_mode, M b9 ;
\ ,pop_ri !!
: pop_sa, M bc ;
: pop_x,  M b8 ;
: dup     M 92 ;            \ push
: push_ct, M 94 ;
\ , push gi
: push_la, _inline M 9d ;
: r> _inline M 9a ;         \ push_lstack
: push_mode, M 91 ;
\ ,push ri !!
: r@ _inline M 80 ;         \ push r0
: over    M 93 ;           \ push s1
: 2pick   M 94 ;          \ push s2
: push_sa, M 9c ;
: push_x, M 98 ;
: replb,  M da ;
: replexp, M b5 ;
\ : ;s M 6e ;		\ ret
: reti,   M 6f ;
: rot     M e4 ;            \ rev
: rnd,    M d1 ;
: shift,  M ee ;
: shiftd, M ef ;
: 2*      M e2 ;
: 8<<     M ec ;        \ shl #8
: shld#1, M e6 ;
: shr#1,  M e3 ;
: shr#8,  M ed ;
: 8>>     M ed ;
: 2/      shr#1, ;
: shrd#1, M e7 ;
: skip,   M 30 ;
: skipc,  M 31 ;
: skipn,  M 32 ;
: skipnc, M 35 ;
: skipp,  M 36 ;
: skipnz, M 37 ;
: skipz,  M 33 ;
: split,  M 99 ;
: st[--r0], M 64 ;
: st[--x],  M 68 ;
: st[r0++], M 66 ;
: st[r0],   M 62 ;
: st[x++],  M 69 ;
: st[x],  M 61 ;
: st[],   M 60 ;
: step,   M 34 ;
: sto[],  M b0 ;
: sto.i[],  M b1 ;
: -       M c8 ;              \ sub
: subb,   M ca ;
: subexp, M d3 ;
: testb,  M d9 ;
: testexp, M d4 ;
: swap    M b2 ;           \ xcg
: xor     M c3 ;

: nip     swap drop ;
: !       st[], drop ;

: up@     M 71 ;
: up!     M 51 ;

: sp!    \ ( 's (emit) dup .x ) 
        pop_sa, drop drop ;
: sp@ 	-2 .quad4 
        scache, drop sdepth, push_sa,
	swap 2* 2* -
\	'S (emit) dup .x 
 	;

\ nochmal testen!
\ : pick  >r
\	-&14 .quad2
\ 	,scache	\ write all to memory
\	,push_sa drop
\	r> cells + @ ;

: pick  dup
	BEGIN dup WHILE rot >r 1- REPEAT
	drop over swap
	BEGIN dup WHILE r> rot rot 1- REPEAT
	drop ;

: rp@   _noinline -&14 .quad2 lcache, push_la,
 	\ ,ldepth 2* 2* -
\	'R (emit) dup .x 
	;

\ : rp! 'r (emit) dup .x pop_la, ;
: rp! _inline pop_la, ;


: um*
  M 50 0 mulu, ;

: um/mod
  M 50 divu, swap ;

: < cmp, drop shr#8, shr#8, shr#8, shr#8, ;