-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwords.asm
More file actions
1442 lines (1317 loc) · 20.8 KB
/
words.asm
File metadata and controls
1442 lines (1317 loc) · 20.8 KB
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
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
DEFWORD enter, 0b01, loaded
PUSHRET esi ; save previous word in return stack
pop esi ; grab new word pointer from call
tnext NEXT
push ebx
mov eax, 4 ; write
mov ebx, 2 ; to stderr
mov edx, retstack+retsz
sub edx, ebp
shr edx, 2
and edx, 255
mov ecx, angles+1
sub ecx, edx
int 0x80
mov eax, 4
lea ecx, [esi-10] ; offset to flags from call enter
mov dl, [ecx]
and edx, 0b00111111 ; get length from flags
sub ecx, edx ; get address of name
int 0x80
mov eax, 4
mov ecx, nlstr
mov edx, 1
int 0x80
pop ebx
NEXT
DEFWORD return, 0b00, enter
POPRET esi ; switch to words at top of return stack
NEXT
DEFWORD lit, 0b01, return
push ebx ; make room in working stack
lodsd ; grab next colon-word token
xchg ebx, eax ; put it on the stack
NEXT
DEFWORD litat, 'lit@', 0b01, lit
push ebx
lodsd
mov ebx, [eax] ; same thing but dereferenced
NEXT
DEFWORD litput, 'lit!', 0b01, litat
lodsd
mov [eax], ebx
pop ebx
NEXT
DEFWORD goto, 0b01, litput
lodsd ; grab next colon-word token
xchg esi, eax ; jump to it
NEXT
DEFWORD gotz, 0b01, goto
test ebx, ebx ; check if top of stack is 0
pop ebx ; consume it
lodsd ; grab next colon-word token
jnz notgon ; skip if not zero
xchg esi, eax ; jump to it
notgon NEXT
DEFWORD gonz, 0b01, gotz
test ebx, ebx ; check if top of stack is 0
pop ebx ; consume it
lodsd ; grab next colon-word token
jz yesgon ; skip if zero
xchg esi, eax ; jump to it
yesgon NEXT
; ( a -- )
DEFWORD jump, 0b00, gonz
xchg eax, ebx
pop ebx
jmp eax
; ( a b c -- b c a )
DEFWORD rot, 0b00, jump
pop eax
pop edx
push eax
push ebx
xchg ebx, edx
NEXT
; ( a b c -- c a b )
DEFWORD rot2, 'rot>', 0b00, rot
pop eax
pop edx
push ebx
push edx
xchg ebx, eax
NEXT
; ( a b -- a b a )
DEFWORD over, 0b00, rot2
pop eax
push eax
push ebx
xchg ebx, eax
NEXT
; ( a b c -- a b c a )
DEFWORD dover, '2over', 0b00, over
pop eax
pop ecx
push ecx
push eax
push ebx
xchg ebx, ecx
NEXT
; ( a -- )
DEFWORD drop, 0b00, dover
pop ebx
NEXT
; ( a a -- )
DEFWORD ddrop, '2drop', 0b00, drop
pop ebx
pop ebx
NEXT
; ( a b -- b )
DEFWORD nip, 0b00, ddrop
pop eax
NEXT
; ( a b -- b a b )
DEFWORD tuck, 0b00, nip
pop eax
push ebx
push eax
NEXT
; ( a -- a a )
DEFWORD dup, 0b00, tuck
push ebx
NEXT
; ( a -- a a? )
DEFWORD cdup, '?dup', 0b00, dup
test ebx, ebx
jz nodup
push ebx
nodup NEXT
; ( a b -- a b a b )
DEFWORD ddup, '2dup', 0b00, cdup
pop eax
push eax ; pop+push is smaller than a mov
push ebx
push eax
NEXT
; ( a b -- b a )
DEFWORD swap, 0b00, ddup
pop eax
xchg ebx, eax
push eax
NEXT
; ( a b c d -- c d a b )
DEFWORD dswap, '2swap', 0b00, swap
pop eax
pop ecx
pop edx
push eax
push ebx
push edx
xchg ebx, ecx
NEXT
; ( a -- stack[a] )
DEFWORD nth, 0b00, dswap
mov ebx, [esp+ebx*4]
NEXT
; ( arg3 arg2 arg1 num -- res )
; note that the 4 stack items will still be consumed even
; if the syscall takes less than 3 args.
DEFWORD syscall, 0b00, nth
xchg eax, ebx ; get syscall number from top of stack
pop ebx ; syscall args
pop ecx
pop edx
int 0x80 ; syscall
xchg ebx, eax ; put return value at our top of stack
NEXT
; ( arg6 arg5 arg4 arg3 arg2 arg1 num -- res )
DEFWORD syscall6, 0b00, syscall
xchg eax, ebx ; get syscall number from top of stack
pop ebx ; syscall args
pop ecx
pop edx
xchg esi, [esp]
xchg edi, [esp+4]
xchg ebp, [esp+8]
int 0x80 ; syscall
xchg ebx, eax ; put return value at our top of stack
pop esi
pop edi
pop ebp
NEXT
; ( count buf fd -- count )
DEFWORD readall, 0b00, syscall6
pop ecx ; buf
pop edx ; count
push ecx ; save orig buf
ragain mov eax, 3 ; read
int 0x80 ; syscall
test eax, eax ; check result
js rneg ; got negative
jz rdone ; read zero
add ecx, eax ; offset amount read
sub edx, eax
jg ragain ; maybe more to read
rdone pop ebx ; get orig buf
sub ebx, ecx ; calc total
neg ebx
NEXT
rneg cmp eax, -4 ; interrupted?
je ragain ; yes, try again
jmp abort ; no, abort
; ( count buf fd -- )
DEFWORD writeall, 0b00, readall
pop ecx ; buf
pop edx ; count
wagain mov eax, 4 ; write
int 0x80 ; syscall
test eax, eax ; result negative?
js wneg ; yes, handle it
add ecx, eax ; offset amount written
sub edx, eax ; check if more needed
jnz wagain ; yes, try again
pop ebx
NEXT
wneg cmp eax, -4 ; interrupted?
je wagain ; yes, try again
jmp abort ; otherwise abort
; ( a b -- a<<b )
DEFWORD lshift, 0b00, writeall
pop ecx
xchg ebx, ecx
shl ebx, cl
NEXT
; ( a b -- a>>b )
DEFWORD rshift, 0b00, lshift
pop ecx
xchg ebx, ecx
shr ebx, cl
NEXT
; ( a b -- a&b )
DEFWORD band, 'and', 0b00, rshift
pop eax
and ebx, eax
NEXT
; ( a b -- a|b )
DEFWORD bor, 'or', 0b00, band
pop eax
or ebx, eax
NEXT
; ( a b -- a^b )
DEFWORD bxor, 'xor', 0b00, bor
pop eax
xor ebx, eax
NEXT
; ( a -- !a )
DEFWORD lnot, 'not', 0b00, bxor
xchg eax, ebx
xor ebx, ebx
test eax, eax
jnz lnotz
inc ebx
lnotz NEXT
; ( a -- ~a )
DEFWORD bnot, '~', 0b00, lnot
not ebx
NEXT
; ( a b -- a+b )
DEFWORD plus, '+', 0b00, bnot
pop eax
add ebx, eax
NEXT
; ( a b -- b-a )
DEFWORD minusinv, '-^', 0b00, plus
pop eax
sub ebx, eax
NEXT
; ( a -- a+1 )
DEFWORD increment, '1+', 0b00, minusinv
add ebx, 1
NEXT
; ( a -- a-1 )
DEFWORD decrement, '1-', 0b00, increment
sub ebx, 1
NEXT
; ( a -- a+4 )
DEFWORD increment4, '4+', 0b00, decrement
add ebx, 4
NEXT
; ( a -- a-4 )
DEFWORD decrement4, '4-', 0b00, increment4
sub ebx, 4
NEXT
; ( a b -- a-b )
DEFWORD minus, '-', 0b00, decrement4
pop eax
xchg ebx, eax
sub ebx, eax
NEXT
; ( a b -- a*b )
DEFWORD mulsigned, '*', 0b00, minus
pop eax
imul ebx, eax
NEXT
; ( a b -- a%b a/b )
DEFWORD divmod, '/mod', 0b00, mulsigned
pop eax
xor edx, edx
div ebx
push edx
xchg ebx, eax
NEXT
; ( a -- -a )
DEFWORD negate, 'neg', 0b00, divmod
neg ebx
NEXT
; ( a -- a>>31 )
DEFWORD isneg, '?neg', 0b00, negate
shr ebx, 31
NEXT
; ( a -- |a| )
DEFWORD absv, 'abs', 0b00, isneg
test ebx, 1<<31
jz alrpos
neg ebx
alrpos NEXT
; ( -- waddr wsize )
DEFWORD getword, 'word', 0b00, absv
push ebx
regetw mov ebx, [wordfd]
mov ecx, wordbuf-1
readchr xor edx, edx
inc edx
xor eax, eax
mov al, 3 ; read
inc ecx ; the next byte
int 0x80 ; syscall
cmp eax, 1 ; did it error?
jne badrd ; yes, give failed
mov al, [ecx] ; no, lets check it
imul eax, 0x020268f8
and eax, 0xa1201040
cmp eax, 0x00001000 ; is whitespace?
jne readchr ; no, loop some more
mov ebx, wordbuf
cmp ecx, ebx ; is /only/ whitespace?
je regetw ; yes, try again
push ebx
sub ecx, ebx
xchg ebx, ecx
mov [wordlen], bl
goodrd NEXT
badrd xor ebx, ebx
push ebx
jmp goodrd
; ( c -- )
DEFWORD emit, 0b00, getword
push ebx
xor eax, eax
mov al, 4
xor ebx, ebx
inc ebx
mov ecx, esp
mov edx, ebx
int 0x80
pop ebx
pop ebx
NEXT
; ( -- str len )
; adds a lil null termination, as a treat (not included in length)
; so that its convenient to use with syscalls that take paths etc
; decrement here after using if you dont want this
DEFWORD string, '"', 0b00, emit
push ebx
mov edi, [here]
push edi
xor eax, eax
mov ebx, [wordfd]
mov ecx, edi
xor edx, edx
inc edx
strread mov al, 3 ; read
int 0x80
cmp [ecx], byte '"'
je strbye
inc ecx
cmp al, 1
je strread
strbye mov ebx, ecx
sub ebx, edi
mov [ecx], byte 0
inc ecx
mov [here], ecx
NEXT
DEFWORD sstring, 's"', 0b10, string
call enter
dd lit, goto
dd dcom
dd litat, here
dd lit, 0
dd dcom
dd string
dd rot
dd litat, here
dd swap
dd dput
dd swap
dd lit, lit
dd dcom
dd dcom
dd lit, lit
dd dcom
dd dcom
dd return
DEFWORD dotstring, '."', 0b10, sstring
call enter
dd sstring
dd lit, emits
dd dcom
dd return
DEFWORD spc, 0b00, dotstring
call enter
dd lit, ' '
dd emit
dd return
DEFWORD nl, 0b00, spc
call enter
dd lit, `\n`
dd emit
dd return
; ( str len -- )
DEFWORD emits, 0b00, nl
call enter
dd swap
dd lit, 1
dd writeall
dd return
; ( addr -- c )
DEFWORD cat, 'c@', 0b00, emits
mov bl, [ebx]
and ebx, 0xff
NEXT
; ( c addr -- )
DEFWORD cput, 'c!', 0b00, cat
pop eax
mov [ebx], al
pop ebx
NEXT
; ( addr -- a )
DEFWORD dat, '@', 0b00, cput
mov ebx, [ebx]
NEXT
; ( a addr -- )
DEFWORD dput, '!', 0b00, dat
pop eax
mov [ebx], eax
pop ebx
NEXT
; ( c -- )
DEFWORD printhexc, '.xc', 0b00, dput
call enter
dd lit, 0xf
dd band
dd lit, hexchr
dd plus
dd cat
dd emit
dd return
; ( c -- )
DEFWORD printhex1, '.x1', 0b00, printhexc
call enter
dd dup
dd lit, 4
dd rshift
dd printhexc
dd printhexc
dd return
; ( s -- )
DEFWORD printhex2, '.x2', 0b00, printhex1
call enter
dd dup
dd lit, 8
dd rshift
dd printhex1
dd printhex1
dd return
; ( a -- )
DEFWORD printhex, '.x', 0b00, printhex2
call enter
dd dup
dd lit, 16
dd rshift
dd printhex2
dd printhex2
dd return
; ( c -- )
DEFWORD print, '.', 0b00, printhex
call enter
dd lit, 10
dd swap
dd dup
dd isneg
dd gotz, pnotn
dd lit, '-'
dd emit
dd absv
pnotn dd lit, 10
dd divmod
dd cdup
dd gonz, pnotn
pprint dd lit, 0x30
dd plus
dd emit
dd dup
dd lit, 10
dd eq
dd gotz, pprint
dd drop
dd return
; ( a b -- a==b )
DEFWORD eq, '=', 0b00, print
pop eax
xchg edx, ebx
xor ebx, ebx
cmp eax, edx
jne eqneq
eqieq inc ebx
eqneq NEXT
; ( a b -- a>b )
DEFWORD gt, '>', 0b00, eq
pop eax
xchg edx, ebx
xor ebx, ebx
cmp eax, edx
jg eqieq
NEXT
; ( a b -- a<b )
DEFWORD lt, '<', 0b00, gt
pop eax
xchg edx, ebx
xor ebx, ebx
cmp eax, edx
jl eqieq
NEXT
; ( a b -- a>=b )
DEFWORD gte, '>=', 0b00, lt
pop eax
xchg edx, ebx
xor ebx, ebx
cmp eax, edx
jge eqieq
NEXT
; ( a b -- a<=b )
DEFWORD lte, '<=', 0b00, gte
pop eax
xchg edx, ebx
xor ebx, ebx
cmp eax, edx
jle eqieq
NEXT
; ( m1 m2 len -- m1==m2 )
DEFWORD memeq, 'mem=', 0b00, lte
xchg ecx, ebx
xor ebx, ebx
pop eax
pop edi
lmemeq mov dl, [eax+ecx-1]
cmp dl, [edi+ecx-1]
jne nmemeq
loop lmemeq
inc ebx
nmemeq NEXT
; ( m1 len m2 -- )
DEFWORD memcpy, 0b00, memeq
pop ecx
pop eax
memcl mov dl, [eax+ecx-1]
mov [ebx+ecx-1], dl
loop memcl
pop ebx
NEXT
; ( str len -- )
DEFWORD strcom, 'str,', 0b00, memcpy
call enter
dd dup
dd rot2
dd litat, here
dd memcpy
dd allot
dd return
; ( str1 len1 str2 len2 -- str1==str2 )
DEFWORD streq, 'str=', 0b00, strcom
call enter
dd rot
dd over
dd eq
dd gotz, nstreq
dd memeq
dd return
nstreq dd ddrop
dd drop
dd lit, 0
dd return
; ( addr -- str len )
DEFWORD dictname, 0b00, streq
call enter
dd lit, 5
dd minus
dd dup
dd cat
dd lit, 0b00111111
dd band
dd tuck
dd minus
dd swap
dd return
; ( addr -- addr )
DEFWORD dictprev, 0b00, dictname
call enter
dd decrement4
dd dat
dd return
; ( addr -- flags )
DEFWORD dictflags, 0b00, dictprev
call enter
dd lit, 5
dd minus
dd cat
dd lit, 6
dd rshift
dd return
; ( flags -- )
DEFWORD dictor, 0b00, dictflags
mov eax, [latest]
shl ebx, 6
or [eax-5], bl
pop ebx
NEXT
; ( -- )
DEFWORD dictcom, ':code', 0b00, dictor
call enter
dd getword
dd cdup
dd gotz, colabrt
dd dup
dd rot2
dd strcom
dd lit, 0b00111111
dd band
dd ccom
dd litat, latest
dd dcom
dd litat, here
dd litput, latest
dd return
; ( -- )
DEFWORD endcode, ';code', 0b00, dictcom
call enter
dd lit, 0xad
dd ccom
dd lit, 0xff
dd ccom
dd lit, 0xe0
dd ccom
dd return
; ( -- )
DEFWORD words, 0b00, endcode
call enter
dd litat, latest
wdsloop dd dup
dd dictname
dd emits
dd spc
dd dictprev
dd cdup
dd gonz, wdsloop
dd nl
dd return
; ( str len -- addr )
DEFWORD find, 0b00, words
call enter
dd litat, latest
findrep dd rot2
dd ddup
dd lit, 4
dd nth
dd dictname
dd streq
dd gonz, findbye
dd rot
dd dictprev
dd dup
dd gonz, findrep
dd rot2
findbye dd ddrop
dd return
; ( -- addr )
DEFWORD wordaddr, `'`, 0b00, find
call enter
dd getword
dd ddup
dd find
dd cdup
dd gotz, innonn
dd rot2
dd ddrop
dd return
; ( -- b )
DEFWORD wordchar, `''`, 0b00, wordaddr
call enter
dd getword
dd gotz, wnowc
dd cat
wnowc dd return
; ( -- a )
DEFWORD if, 0b10, wordchar
call enter
dd lit, gotz
dd dcom
dd litat, here
dd lit, 0
dd dcom
dd return
; ( a -- a )
DEFWORD else, 0b10, if
call enter
dd lit, goto
dd dcom
dd litat, here
dd lit, 0
dd dcom
dd dup
dd increment4
dd rot
dd dput
dd return
; ( a -- )
DEFWORD then, 0b10, else
call enter
dd litat, here
dd swap
dd dput
dd return
DEFWORD bthen, '[then]', 0b00, then
NEXT
; ( b -- )
DEFWORD bif, '[if]', 0b00, bthen
call enter
dd gonz, bifret
bifin dd getword
dd lit, bthen-11 ; location of '[then]'
dd lit, 6 ; length of '[then]'
dd streq
dd gotz, bifin
bifret dd return
; ( -- a )
DEFWORD begin, 0b10, bif
call enter
dd litat, here
dd return
; ( a -- )
DEFWORD while, 0b10, begin
call enter
dd lit, gonz
dd dcom
dd dcom
dd return
; ( a -- )
DEFWORD until, 0b10, while
call enter
dd lit, gotz
dd dcom
dd dcom
dd return
; ( a -- )
DEFWORD loop, 0b10, until
call enter
dd lit, goto
dd dcom
dd dcom
dd return
DEFWORD breakglass, 0b00, loop
push ebx
xor eax, eax
mov al, 125 ; mprotect
mov ebx, starttext ; first word
shr ebx, 12 ; page crimes
shl ebx, 12
mov ecx, endtext ; length of text section
sub ecx, ebx
xor edx, edx
mov dl, 7 ; PROT_READ|PROT_WRITE|PROT_EXEC
int 0x80
test eax, eax
jnz abort
pop ebx
NEXT
DEFWORD trace, 0b00, breakglass
call enter
dd breakglass
dd lit, 0x53909090
dd litput, tnext
dd return
DEFWORD untrace, 0b00, trace
call enter
dd breakglass
dd lit, 0x53e0ffad
dd litput, tnext
dd return
; ( addr len -- )
DEFWORD wdump, 0b00, untrace
call enter
dumploo dd cdup
dd gotz, dbye
dd swap
dd dup
dd dat
dd printhex
dd spc
dd increment4
dd swap
dd decrement
dd goto, dumploo
dbye dd drop
dd return
; ( -- h )
DEFWORD stackheight, 0b00, wdump
mov eax, esp
push ebx
mov ebx, [stackstart]
sub ebx, eax
shr ebx, 2
NEXT
; ( -- p )
DEFWORD stackpos, 0b00, stackheight
mov eax, esp
push ebx
xchg ebx, eax
NEXT
DEFWORD printstack, '.S', 0b00, stackpos
call enter
dd stackheight
dd stackpos
dd swap
dd wdump
dd nl
dd return
DEFWORD bye, 0b00, printstack
call enter
dd lit, 0 ; success
dd lit, 1 ; nr_exit
dd syscall
abrtstr db ' '
DEFWORD abort, 0b00, bye
call enter
dd lit, abrtstr
dd lit, 6
dd emits
dd restart
; ( a -- a )
DEFWORD cabort, '?abort', 0b00, abort
test ebx, ebx
jz abort
NEXT
; ( str len -- str len b )
DEFWORD startsnum, '?num', 0b00, cabort
pop edx
push edx
push ebx
xor ebx, ebx
xor eax, eax
mov al, [edx]
imul eax, 0xff706015
and eax, 0xe0001ee4
cmp eax, 0xe00002c4
jle notanum
inc ebx
notanum NEXT
; ( str len -- num )
DEFWORD parsenum, 0b00, startsnum
pop edx ; str ptr
xchg ecx, ebx ; length
xor ebx, ebx ; result
xor eax, eax
mov al, '$'
cmp al, [edx] ; is hex?
mov al, 10 ; decimal
jne numst
mov al, 16 ; hex
inc edx ; skip the $
dec ecx
numst mov edi, eax
numloop imul ebx, edi
mov al, [edx]
cmp al, 0x41 ; handle hex >9
jl numnob
add eax, 9
numnob and eax, 15
add ebx, eax
inc edx
loop numloop
NEXT
stunstr db ' stack underflow'
DEFWORD chkstack, 0b00, parsenum
cmp esp, [stackstart]
jle cstkok
mov esp, [stackstart]
xor ebx,ebx