-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdict.tasm
913 lines (790 loc) · 16.4 KB
/
dict.tasm
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
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
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
# dict -- forth-like dictionary definition and lookup
#>>>>>>to do
# routines:
# def
# (must trim off trailing char)
# check if lookup ignores trailing char. it should.
# ...
# check for old stack names slipping through:
# Edit ,y/#.*/x/b[s]tack/=
# Edit ,y/#.*/y/stackreg1bak/x/[^a-z][s]tack/=
# if any found, convert: bstack->dstack, stack->rstack
# speaking of old names, i hope i've fully recovered from
# accidentally global replace: ,x/def(\.name)?/c/memcopy/
# update namespace comment
### dictionary entry format
# 1 codeword
# 1 next entry
# 1 namelen
# n namechars
# 1 deflen
# n def
#
# 'null' next entry is +++++++++.
# can't use 0. mni is reasonable, but mpi is more so;
# an entry won't fit if it starts at mpi.
# xt points to codeword? i guess that's right.
# tests & behaviour specification in dict.tests
# namespace usage:
# stack* dstack* rstack* dpush dpop rpush rpop
# dict* key* word* lookup* alloc*
# commands:
# (not really doing built-in words yet.)
# def
# the next word is the name.
# following words are the definition, up to '-d-'.
# internal routines:
# word
# read a word
# i think i want this first
# i think word should set up key interrupts, spin while the word is typed,
# and then clear interrupts and return. yes.
# lookup
# find a word in the dictionary
# alloc
# alloc memory
# swap
# stack operation
# how to arrange memory?
# stacks at top, of course.
# dict needs to grow somewhere.
# input buffer also required.
# i guess input buffer can be a fixed size.
# in fact, it should be, thats the simple way.
# what size?
# 216 = 3 lines. hmm.
# if it reads a word at a time, words in a definition can go in the dictionary
# as soon as they're entered. interpreting forth similarly would run each
# word after it is read. no need for big buffer. yay!
# now what size? :)
# mpi of 3 trits is 13. 13 characters would be quite indulgent
# for a real language on a 19KW machine.
# 13 it is, then. -- note: now includes terminating space or enter.
# oh that's 14 including the 0. ok then.
# also need alloc routine for dict.
# buffer can be alloc'd too.
gotodata;>start
#######################
### stack data
null;+++++++++;rstackbase
null;;rstacktop
null;;stackreg1bak
null;++++-----;dstackbase
null;;dstacktop
# some dstackbase values with space for
# the 2 stacks and remaining memory:
# ++++----- 242 19441 1%
# +++------ 728 18955 3%
# ++------- 2186 17497 11%
# +-------- 6560 13123 33% lol
#######################
### dict global data
null;;dict
null;;alloc.next
#######################
### stack init
romread1;>rstackbase;start
setdata;>rstacktop
# if not using bstack omit remainder
romread1;>dstackbase
setdata;>dstacktop
# underflow marker for data stack:
setreg1;-+-+-+-+-
gotodata;>dpush
#######################
### dict init
setreg1;>alloc.base
setdata;>alloc.next
monofill;-------00
setreg1;00000+---
setdata;>word.buflen
gotodata;>dpush
gotodata;>alloc
gotodata;>dpop
setdata;>word.bufaddr
## intern def
# alloc 7 words for an entry with an empty definition
setreg1;000000+-+
gotodata;>dpush
gotodata;>alloc
gotodata;>dpop
# it's the head of the dictionary now
setdata;>dict
ptset
# set the codeword
setreg1;>def
ptwri
# set the 'next' field to null
ptinc
setreg1;+++++++++
ptwri
# name length
ptinc
setreg1;0000000+0
ptwri
# set the name
# not sure if the chars will work like this
ptinc
setreg1;:d
ptwri
ptinc
setreg1;:e
ptwri
ptinc
setreg1;:f
ptwri
# set the definition length
ptinc
setreg1;000000000
ptwri
#######################
### dict main loop
setreg1;>mainloop.ret.1;mainloop
gotodata;>rpush
gotodata;>word
setreg1;>mainloop.ret.2;mainloop.ret.1
gotodata;>rpush
gotodata;>lookup
## pop and test xt
gotodata;>dpop;mainloop.ret.2
setreg2;>+++++++++
gotodataif;>mainloop.badword
# fetch codeword, call it
setdata;>mainloop.getcw
# cheat with the return address:
setreg1;>mainloop
gotodata;>rpush
romread1;000000000;mainloop.getcw
gotoreg1
# called routine needs word address.
# it can fetch it from mainloop.getcw.
# i'm not sure there's a better way to do that.
# maybe i'll find one later.
TTYwrite;:?;mainloop.badword
TTYwrite;:space
gotodata;>mainloop
#######################
### dict routines
# if unstated, these preserve mempoint but use reg1 & reg2.
###########
## alloc
# subroutine
# ( size -- address )
#romread1;>alloc.next;alloc
#gotodata;>dpush
#gotodata;>swap
#gotodata;>dpop
#romread2;>alloc.next
#add
#setdata;>alloc.next
#gotodata;>rpop
#gotoreg1
# alternative alloc doesnt call swap.
# uses a location for temporary storage,
# which swap did anyway.
romread1;>alloc.next;alloc
setdata;>alloc.tmp
gotodata;>dpop
romread2;>alloc.next
add
setdata;>alloc.next
romread1;>alloc.tmp
gotodata;>dpush
gotodata;>rpop
gotoreg1
null;;alloc.tmp
###########
## strsee -- codeword for textual defs
# subroutine
# ( - )
# uses mempoint
# gets current word address from mainloop.getcw
romread1;>mainloop.getcw;strsee
ptset
ptinc
ptinc
ptread
copy1to2
# namelen in 2
ptinc
ptget
# addr of namechars in 1
add
# addr of deflen in 1
ptset
ptread
copy1to2
# deflen in 2
ptinc
ptget
# addr of def in 1
add
copy1to2
# end of def in 2
ptread;;strsee.loop
# cheap. ought to use offsetlen
setdata;>strsee.write
TTYwrite;;strsee.write
ptinc
ptget
gotodataif;>strsee.done
gotodata;>strsee.loop
gotodata;>rpop;strsee.done
gotoreg1
###########
## memcopy
# subroutine
# ( source dest length -- )
# uses mempoint
# copies data from one memory region to another.
# overlap is safe only if dest <= source.
setreg1;000000000;memcopy
setdata;>memcopy.count
gotodata;>dpop
setdata;>memcopy.length
gotodata;>dpop
setdata;>memcopy.dest
gotodata;>dpop
setdata;>memcopy.source
romread1;>memcopy.source;memcopy.loop
romread2;>memcopy.count
add
ptset
ptread
setdata;>memcopy.char
romread1;>memcopy.dest
romread2;>memcopy.count
add
ptset
romread1;>memcopy.char
ptwri
romread1;>memcopy.count
setreg2;00000000+
add
romread2;>memcopy.length
gotodataif;>memcopy.done
setdata;>memcopy.count
gotodata;>memcopy.loop
gotodata;>rpop;memcopy.done
gotoreg1
null;;memcopy.source
null;;memcopy.dest
null;;memcopy.length
null;;memcopy.count
null;;memcopy.data
###########
## def -- define words interactively
# subroutine
# ( - )
# uses mempoint
# uses alloc.next, writing to memory before using alloc
# to claim the space. not terribly good practice, i know.
# stages:
# 1: read word for name
# 2: read any number of words for definition
###
# begin building new entry
romread1;>alloc.next;def
setdata;>def.e.base
ptset
setreg1;>strsee
ptwri
ptinc
romread1;>dict
ptwri
###
# get name, inter that
ptinc
ptget
setdata;>def.e.here
# here now points to namelen
setreg1;>def.ret.name
gotodata;>rpush
gotodata;>word
# fetch length, but don't write it to entry yet because
# we're going to check if it needs pruning.
gotodata;>dpop;def.ret.name
setdata;>def.len
gotodata;>dpop
setdata;>def.s.base
# prune last char from name
# check if last char is space or newline.
# if yes, prune, if no, beep and don't prune.
romread2;>def.len
add
ptset
ptdec
ptread
setreg2;:space
gotodataif;>def.prune
setreg2;:enter
gotodataif;>def.prune
buzzer;---0-----
romread1;>def.len
gotodata;>def.setnamelen
romread1;>def.len;def.prune
setreg2;00000000-
add
setdata;>def.len
romread1;>def.e.here;def.setnamelen
ptset
romread1;>def.len
ptwri
# copy name in
ptinc
ptget
setdata;>def.e.here
# here now points to start of name
romread1;>def.s.base
gotodata;>dpush
romread1;>def.e.here
dotodata;>dpush
romread1;>def.len
gotodata;>dpush
setreg1;>def.name.copied
gotodata;>rpush
gotodata;>memcopy
# oh oh oh oh! found a major bug when making copy code its
# own subroutine: the name would have overwritten the header.
# big argument for not making monolithic routines.
###
# get words, inter them
# loop getting words, copying them in, checking for -d- to end.
# keep a running count of the length.
romread1;>def.e.here;def.name.copied
romread2;>def.len
add
setdata;>def.e.here
# here now points to deflen
>>>>>>>>>>
# set head of dictionary to new definition, and return
romread1;>def.e.base
setdata;>dict
gotodata;>rpop
gotoreg1
# def.e is the new entry
null;;def.e.base
null;;def.e.here
# def.s is source string
null;;def.s.base
# some apply to both
null;;def.len
###########
## lookup
# subroutine
# ( addr len -- xt )
# uses mempoint
gotodata;>dpop;lookup
setdata;>lookup.charcount
gotodata;>dpop
setdata;>lookup.s.base
romread1;>dict
setdata;>lookup.e.xt;lookup.entryloop
ptset
ptinc
# "next"
ptread
setdata;>lookup.e.next
ptinc
# "namelen"
ptread
romread2;>lookup.charcount
gotodataif;>lookup.lenmatch
gotodata;>lookup.nextentry
ptinc;lookup.lenmatch
# "namechars"; want the address this time.
ptget
setdata;>lookup.e.base
setreg1;000000000
setdata;>lookup.i
romread1;>lookup.e.base;lookup.charloop
romread2;>lookup.i
add
ptset
# i'd like to use offsetlen to get only the 6 trits,
# but i don't want to add 4 more instructions for every character.
# i suppose masking the register after load would be better this time,
# only 2 instructions.
ptread
setdata;>lookup.char
romread1;>lookup.s.base
romread2;>lookup.i
add
ptset
ptread
setreg2;000000000;lookup.char
gotodataif;>lookup.charloop.next
gotodata;>lookup.nextentry
# char matched, try the next one.
# if there's no next one, we got a match!
romread1;>lookup.i;lookup.charloop.next
setreg2;00000000+
add
setdata;>lookup.i
romread2;>lookup.charcount
gotodataif;>lookup.gotmatch
gotodata;>lookup.charloop
romread1;>lookup.e.xt;lookup.gotmatch
gotodata;>dpush
gotodata;>rpop
gotoreg1
# length or some char didn't match, so
# fetch & check the next entry pointer.
# if null, return failure.
romread1;>lookup.e.next;lookup.nextentry
setreg2;+++++++++
gotodataif;>lookup.notfound
# valid pointer, so fetch the next xt & put it in reg1
ptset
ptread
gotodata;>lookup.entryloop
copy2to1;lookup.notfound
gotodata;>dpush
gotodata;>rpop
gotoreg1
null;;lookup.s.base
null;;lookup.charcount
null;;lookup.i
null;;lookup.e.xt
null;;lookup.e.base
null;;lookup.e.next
###########
## swap
# subroutine
# ( a b -- b a )
# exchange the top two elements of the data stack
# from scal
# 44 instructions counting the push and pop routines.
# could write a much more efficient one by using mempoint,
# but this is not used since i changed alloc.
#gotodata;>dpop;swap
#setdata;>swap.a
#gotodata;>dpop
#setdata;>swap.b
#romread1;>swap.a
#gotodata;>dpush
#romread1;>swap.b
#gotodata;>dpush
#gotodata;>rpop
#gotoreg1
#
#null;;swap.a
#null;;swap.b
###########
## word
# subroutine
# ( -- address length )
# uses mempoint
# input a word from the keyboard.
# return a string, including the terminating space or enter.
# sets up interrupts and clears them again; lots of lines!
# this is basically a blocking read from the keyboard.
monofill;-------00;word
setreg1;000000000
setdata;>word.count
setkeyint;:1
keyint;>key.1
setkeyint;:2
keyint;>key.2
setkeyint;:3
keyint;>key.3
setkeyint;:4
keyint;>key.4
setkeyint;:5
keyint;>key.5
setkeyint;:6
keyint;>key.6
setkeyint;:7
keyint;>key.7
setkeyint;:8
keyint;>key.8
setkeyint;:9
keyint;>key.9
setkeyint;:0
keyint;>key.0
setkeyint;:-
keyint;>key.neg
setkeyint;:+
keyint;>key.pos
setkeyint;:a
keyint;>key.a
setkeyint;:b
keyint;>key.b
setkeyint;:c
keyint;>key.c
setkeyint;:d
keyint;>key.d
setkeyint;:e
keyint;>key.e
setkeyint;:f
keyint;>key.f
setkeyint;:g
keyint;>key.g
setkeyint;:h
keyint;>key.h
setkeyint;:i
keyint;>key.i
setkeyint;:j
keyint;>key.j
setkeyint;:k
keyint;>key.k
setkeyint;:z
keyint;>key.z
setkeyint;:l
keyint;>key.l
setkeyint;:m
keyint;>key.m
setkeyint;:n
keyint;>key.n
setkeyint;:o
keyint;>key.o
setkeyint;:p
keyint;>key.p
setkeyint;:q
keyint;>key.q
setkeyint;:r
keyint;>key.r
setkeyint;:s
keyint;>key.s
setkeyint;:t
keyint;>key.t
setkeyint;:u
keyint;>key.u
setkeyint;:v
keyint;>key.v
setkeyint;:w
keyint;>key.w
setkeyint;:x
keyint;>key.x
setkeyint;:y
keyint;>key.y
setkeyint;:z
keyint;>key.z
setkeyint;:space
keyint;>key.space
setkeyint;:enter
keyint;>key.enter
# near-white rectangle to signify ready:
setmonovect;---0-0---
monorect;---0+0++-
gotodata;>word.spinloop;word.spinloop
clearkeyint;+++++++++;word.finalize
monofill;-------00
romread1;>word.bufaddr
gotodata;>dpush
romread1;>word.count
gotodata;>dpush
gotodata;>rpop
gotoreg1
null;;word.count
null;;word.bufaddr
null;;word.buflen
## key routines for word
# keyproc is common to all of them
setdata;>word.keytmp;word.keyproc
romread1;>word.bufaddr
romread2;>word.count
add
ptset
romread1;>word.keytmp
ptwri
setreg1;00000000+
add
# now reg1 contains count+1
setdata;>word.count
romread2;>word.buflen
gotodataif;>word.keyproc.beep
romread1;>word.keytmp
setreg2;:space
gotodataif;>word.finalize
setreg2;:enter
gotodataif;>word.finalize
gotodata;>word.spinloop
clearkeyint;+++++++++;word.keyproc.beep
#buzzer;----00000
# i do not want the delay of the buzzer instruction here.
# sfreq/splay/sstop would be no improvement, it's only 0.2ms until return.
# make a "bgbuzz" thread or an sstop thread.
gotodata;>word.finalize
null;;word.keytmp
## key interrupt routines:
TTYwrite;:space;key.space
setreg1;000-0-00+
gotodata;>word.keyproc
TTYwrite;:enter;key.enter
setreg1;000-0-000
gotodata;>word.keyproc
TTYwrite;:+;key.pos
setreg1;000--++-+
gotodata;>word.keyproc
TTYwrite;:-;key.neg
setreg1;000--++0+
gotodata;>word.keyproc
## autogenerate most key interrupt routines:
# the type of operation doesn't really accommodate sed -n
# with /regexp/p, it's shorter and easier to use grep.
# i could make it cover enter space + and - too,
# but it's not worth the extra code.
# <grep '......[a-z0-9]$' ../textdocs/SBTCVM-6-trit-Text-encoding.txt | sed 's/(.+)(.)/TTYwrite;:\2;key.\2\nsetreg1;000\1\ngotodata;>word.keyproc/'
#[
TTYwrite;:a;key.a
setreg1;000------
gotodata;>word.keyproc
TTYwrite;:b;key.b
setreg1;000-----0
gotodata;>word.keyproc
TTYwrite;:c;key.c
setreg1;000-----+
gotodata;>word.keyproc
TTYwrite;:d;key.d
setreg1;000----0-
gotodata;>word.keyproc
TTYwrite;:e;key.e
setreg1;000----00
gotodata;>word.keyproc
TTYwrite;:f;key.f
setreg1;000----0+
gotodata;>word.keyproc
TTYwrite;:g;key.g
setreg1;000----+-
gotodata;>word.keyproc
TTYwrite;:h;key.h
setreg1;000----+0
gotodata;>word.keyproc
TTYwrite;:i;key.i
setreg1;000----++
gotodata;>word.keyproc
TTYwrite;:j;key.j
setreg1;000---0--
gotodata;>word.keyproc
TTYwrite;:k;key.k
setreg1;000---0-0
gotodata;>word.keyproc
TTYwrite;:l;key.l
setreg1;000---0-+
gotodata;>word.keyproc
TTYwrite;:m;key.m
setreg1;000---00-
gotodata;>word.keyproc
TTYwrite;:n;key.n
setreg1;000---000
gotodata;>word.keyproc
TTYwrite;:o;key.o
setreg1;000---00+
gotodata;>word.keyproc
TTYwrite;:p;key.p
setreg1;000---0+-
gotodata;>word.keyproc
TTYwrite;:q;key.q
setreg1;000---0+0
gotodata;>word.keyproc
TTYwrite;:r;key.r
setreg1;000---0++
gotodata;>word.keyproc
TTYwrite;:s;key.s
setreg1;000---+--
gotodata;>word.keyproc
TTYwrite;:t;key.t
setreg1;000---+-0
gotodata;>word.keyproc
TTYwrite;:u;key.u
setreg1;000---+-+
gotodata;>word.keyproc
TTYwrite;:v;key.v
setreg1;000---+0-
gotodata;>word.keyproc
TTYwrite;:w;key.w
setreg1;000---+00
gotodata;>word.keyproc
TTYwrite;:x;key.x
setreg1;000---+0+
gotodata;>word.keyproc
TTYwrite;:y;key.y
setreg1;000---++-
gotodata;>word.keyproc
TTYwrite;:z;key.z
setreg1;000---++0
gotodata;>word.keyproc
TTYwrite;:0;key.0
setreg1;000--0++0
gotodata;>word.keyproc
TTYwrite;:1;key.1
setreg1;000--0+++
gotodata;>word.keyproc
TTYwrite;:2;key.2
setreg1;000--+---
gotodata;>word.keyproc
TTYwrite;:3;key.3
setreg1;000--+--0
gotodata;>word.keyproc
TTYwrite;:4;key.4
setreg1;000--+--+
gotodata;>word.keyproc
TTYwrite;:5;key.5
setreg1;000--+-0-
gotodata;>word.keyproc
TTYwrite;:6;key.6
setreg1;000--+-00
gotodata;>word.keyproc
TTYwrite;:7;key.7
setreg1;000--+-0+
gotodata;>word.keyproc
TTYwrite;:8;key.8
setreg1;000--+-+-
gotodata;>word.keyproc
TTYwrite;:9;key.9
setreg1;000--+-+0
gotodata;>word.keyproc
#]
#######################
### stack routines
## rpush
# pushes reg1 to the return stack
# trashes reg1, reg2
setdata;>stackreg1bak;rpush
romread1;>rstacktop
setdata;>rstackpushme
romread1;>stackreg1bak
setdata;000000000;rstackpushme
romread1;>rstacktop
setreg2;00000000-
add
setdata;>rstacktop
continue
## rpop
# pops top of return stack into reg1
# trashes reg2
romread1;>rstacktop;rpop
setreg2;00000000-
subtract
setdata;>rstacktop
setdata;>rstackpopme
romread1;000000000;rstackpopme
continue
## dpush
# pushes reg1 to b stack
# trashes reg1, reg2
setdata;>stackreg1bak;dpush
romread1;>dstacktop
setdata;>dstackpushme
romread1;>stackreg1bak
setdata;000000000;dstackpushme
romread1;>dstacktop
setreg2;00000000+
add
setdata;>dstacktop
romread1;>stackreg1bak
continue
## dpop
# pops top of b stack into reg1
# trashes reg2
romread1;>dstacktop;dpop
setreg2;00000000+
subtract
setdata;>dstacktop
setdata;>dstackpopme
romread1;000000000;dstackpopme
continue
#######################
### end of code
stop;;alloc.base