Differences From Artifact [0be4e70044]:

  • File src/dxforth/dxforth.asm.m4 — part of check-in [77d9e83273] at 2017-12-24 06:44:14 on branch dxforth — Cleanup unnecessary code (user: kc5tja size: 32764)

To Artifact [73281fff57]:

  • File src/dxforth/dxforth.asm.m4 — part of check-in [7bd9f4f4bd] at 2018-01-07 09:56:14 on branch dxforth — HEX DECIMAL and BINARY (user: kc5tja size: 34844)

67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81







-
+







assoc(`twodrop',   `2DROP   ')
assoc(`ntib',      `#TIB    ')
assoc(`tib',       `TIB     ')
assoc(`accept',    `ACCEPT  ')
assoc(`key',       `KEY     ')
assoc(`base',      `BASE    ')
assoc(`cmove',     `CMOVE   ')
assoc(`dbg',       `DBG     ')
assoc(`bye',       `BYE     ')
assoc(`drop',      `DROP    ')
assoc(`dup',       `DUP     ')
assoc(`emit',      `EMIT    ')
assoc(`evaluate',  `EVALUATE')
assoc(`execute',   `EXECUTE ')
assoc(`exit',      `EXIT    ')
assoc(`fill',      `FILL    ')
132
133
134
135
136
137
138
















139
140
141
142
143
144
145
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







assoc(`cstore',    `C!      ')
assoc(`plussto',   `+!      ')
assoc(`mult',      `*       ')
assoc(`minus',     `-       ')
assoc(`plus',      `+       ')
assoc(`store',     `!       ')
assoc(`fetch',     `@       ')
assoc(`pad',       `PAD     ')
assoc(`hld',       `HLD     ')
assoc(`hold',      `HOLD    ')
assoc(`todigit',   `>DIGIT  ')
assoc(`nstart',    `<#      ')
assoc(`nnn',       `#       ')
assoc(`nns',       `#S      ')
assoc(`nend',      `#>      ')
assoc(`umdivmod',  `UM/MOD  ')
assoc(`udot',      `U.      ')
assoc(`dot',       `.       ')
assoc(`is_lt0',    `0<      ')
assoc(`abs',       `ABS     ')
assoc(`hex',       `HEX     ')
assoc(`decimal',   `DECIMAL ')
assoc(`binary',    `BINARY  ')

; DX-Forth is intended to be loaded at address $14200, and not
; exceed $17FFF.  The dictionary space is intended to occupy
; from $18000-$1BFFF.  Somewhere in this space must also exist
; things like the Forth stacks and block buffers.
;
; The following memory map crudely represents the memory layout
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
182
183
184
185
186
187
188

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208







-
+










+
+







; Execute the next Forth virtual instruction.

next:	lhu	W,0(I)
	addi	I,I,2
	add	W,W,D
	jalr	x0,0(W)

dbg:	jalr	x0,0(x0)
_bye:	jalr	x0,0(x0)

; ==== COLD
;
; Note that some words need relative references defined here
; to resolve circular dependencies.  E.g., we must invoke QUIT
; from here, despite QUIT being defined much later in the
; listing.

squote = _squote - _start
lit16 = _lit16 - _start
lit32 = _lit32 - _start
lit64 = _lit64 - _start

	align	4
_cold:	jal	W,_docol
_cold_0:
	hword	quit, wedge	; Quit should never return.

; Indirect branch to a new location.
426
427
428
429
430
431
432








433
434
435
436
437
438
439
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465







+
+
+
+
+
+
+
+







	align	4
_is_lt:
	ld	W,0(S)
	addi	S,S,8
	blt	W,T,_rtnT
_rtnF:	addi	T,x0,0
	jal	x0,next

; Sets T to -1 if T<0; 0 otherwise.

	align	4
_is_lt0:
	blt	T,x0,_rtnT
	addi	T,x0,0
	jal	x0,next

; Bitwise AND, OR, XOR.

	align	4
__and:
	ld	W,0(S)
	addi	S,S,8
456
457
458
459
460
461
462




463
464
465
466
467
468
469
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499







+
+
+
+








	align	4
_negate:
	xori	T,T,-1
	addi	T,T,1
	jal	x0,next

	align	4
_abs:	blt	T,x0,_negate
	jal	x0,next

	align	4
__2star:
	slli	T,T,1
	jal	x0,next

	align	4
__2slash:
703
704
705
706
707
708
709












710
711
712
713
714
715
716
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758







+
+
+
+
+
+
+
+
+
+
+
+







                ld      t1, 32(sp)
                ld      t2, 40(sp)
                ld      t3, 48(sp)
                addi    sp, sp, 56
                jalr    x0, 0(ra)

; End routines.

; UM/MOD ( ud u -- r q )

	align	4
_umdivmod:
	addi	a2,T,0
	ld	a1,0(S)
	ld	a0,8(S)
	jal	ra,mathUDivMod
	sd	a1,8(S)
	addi	S,S,8
	jal	x0,next

; M* ( a b -- a*b.L a*b.H )
;
; This implementation isn't particularly efficient.  But,
; it should be correct.

	align	4
1132
1133
1134
1135
1136
1137
1138
























































1139
1140
1141
1142
1143
1144
1145
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	jal	W,_docol
	hword	over, plus, end, store
	hword	dup, strt, store, cur, store
_accept_0:
	hword	key, bs, c_c, c_m, gr, drop, go, _accept_0 - _start

; END ACCEPT

; BEGIN PICTURED NUMERIC OUTPUT

	align	4
_pad:	jal	W,_docol
	hword	lit32
	align	4
	word	_quit_0 + 256 + $14200		; Base this on HERE when we implement it.
	hword	exit

	align	4
_hld:	jal	W,_dovar
	align	8
	dword	0

	align	4
_hold:	jal	W,_docol
	hword	lit16, -1, hld, plussto, hld, fetch, cstore, exit

	align	4
_todigit:
	jal	W,_docol
	hword	dup, lit16, 10, is_geu, zgo, _todigit_0
	hword	lit16, 7, plus
_todigit_0:
	hword	lit16, $30, plus, exit

	align	4
_nstart:
	jal	W,_docol
	hword	pad, hld, store, exit

	align	4
_nend:	jal	W,_docol
	hword	drop, hld, fetch, pad, over, minus, exit

	align	4
_nnn:	jal	W,_docol	; nn: is taken elsewhere.
	hword	lit16, 0, base, fetch, umdivmod, swap, todigit, hold, exit

	align	4
_nns:	jal	W,_docol
_nns_0:	hword	dup, zgo, _nns_1, nnn, go, _nns_0
_nns_1: hword	exit

	align	4
_udot:	jal	W,_docol
	hword	nstart, nns, nend, type, exit

	align	4
_dot:	jal	W,_docol
	hword	dup, is_lt0, tor, abs, nstart, nns, rfrom
	hword	zgo, _dot_0, lit16, $2D, hold
_dot_0:	hword	nend, type, exit

; END PICTURED NUMERIC OUTPUT

; ==== Look stuff up in the dictionary.
;
; The dictionary is a mapping of word name to code field
; address (CFA).  The dictionary is expressed as a relational
; table with the following schema:
;
1403
1404
1405
1406
1407
1408
1409














1410
1411
1412
1413
1414
1415
1416
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528







+
+
+
+
+
+
+
+
+
+
+
+
+
+







	hword	exit

	align	4
_base:	jal	W,_dovar
	align	8
	dword	10

	align	4
_hex:	jal	W,_docol
	hword	lit16, 16, base, store, exit

	align	4
_decimal:
	jal	W,_docol
	hword	lit16, 10, base, store, exit

	align	4
_binary:
	jal	W,_docol
	hword	lit16, 2, base, store, exit

	align	4
sign = _sign - _start
_sign:	jal	W,_dovar
	align	8
	dword	0

	align	4
1507
1508
1509
1510
1511
1512
1513
1514
1619
1620
1621
1622
1623
1624
1625








-
	hword	type, cr, exit

	align	4
_quit:	lui	R,$14000		; Hard reset of return stack.
	jal	W,_docol
_quit_0:
	hword	cr, rep, go, _quit_0