-
Notifications
You must be signed in to change notification settings - Fork 2
/
forth.asm
2038 lines (1817 loc) · 41 KB
/
forth.asm
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
;;; Register allocations
;;; r0: Top of stack (TOS)
;;; r1: Forth instruction pointer (IP)
;;; r2: Return stack pointer (RSP)
;;; r3: User pointer (HERE)
;;; r10: Terminal port
;;; sp: Parameter stack pointer (PSP)
;;; r4 - r9: unassigned
;;; r11 - r13: unassigned
;;; Hidden flag is 64
;;; Immediate flag is 128
;;; Length mask is 31
;;; word header:
;;; 0: previous entry
;;; 1: length + flags
;;; 2-4: first three characters of name
;;; 5 onwards: data
%include "common"
start:
;; Check if this is a reboot.
cmp [rebooted], 0
jne did_reboot
didnt_reboot:
;; If not, let's set up the HERE pointer.
;; otherwise our word definitions get clobbered.
mov r3, here_start
mov [var_here], r3
jmp main_asm
did_reboot:
jmp main_asm
main_asm:
mov [var_state], 0
mov r0, 0x2000
mov [0x1FFF], r0
mov r0, 0x1000
mov [0x0FFF], r0
mov r0, 0x0800
mov [0x07FF], r0
mov r0, 0xFFFF
;; Regardless of whether or not we rebooted, we do the
;; following.
;; Set up stack pointer (adjusts automatically to memory space)
mov sp, [r0]
mov [stack_zero_prog], sp
;; User stack zero
push 0
mov [stack_zero], sp
;; Allocate 64 stack items before placing return stack.
mov r2, sp
mov r4, 64
sub r2, r4
;; Set here_end
mov r4, 64
mov r0, r2
sub r0, r4
mov [var_here_end], r0
;; In case we call EXIT from the top level.
sub r2, 1
mov [r2], interpret_done
mov r10, 0
bump r10
send r10, 0x200F
mov r1, main
jmp next
main:
dw lit, rebooted, fetch
dw lit, 1, lit, rebooted, store
dw zjump, main_cont
clear_reboot:
;; dw lit, str_buffer, lit, 128, erase
dw page
main_cont:
dw welcome_proc
dw lit, 0x200F, term_send
dw lit, 0x1020, term_send
dw lit, inputdata_prompt, puts
dw lit, str_buffer, lit, 128, lit, 0x1022, getline
dw lit, str_buffer, lit, input_ptr, store
dw page
interpret_loop:
dw colorize_state
dw check_underflow
dw word, qdup, zjump, interpret_done
dw find, qdup, zjump, maybe_number
dw state, fetch, zjump, interpret_word
compiling_word:
dw dup, qimmed, zjump, compile_word
;; Word is immediate, special yellow color
dw lit, 0x200E, term_send
interpret_word:
dw lit, word_buffer, puts, space
dw to_cfa, execute
dw jump, interpret_loop
compile_word:
dw lit, word_buffer, puts, space
dw to_cfa, comma, jump, interpret_loop
maybe_number:
dw lit, word_buffer, number
dw lit, num_status, fetch, zjump, not_found
dw state, fetch, zjump, interpret_number
compile_number:
dw lit, lit, comma, comma
dw lit, 0x2009, term_send
dw lit, word_buffer, puts, space
dw jump, interpret_loop
interpret_number:
dw lit, 0x200B, term_send
dw lit, word_buffer, puts, space
dw jump, interpret_loop
colorize_state:
call docol
dw state, fetch, zjump, colorize_interp
;; red for compiling
dw lit, 0x200C, term_send
dw exit
colorize_interp:
;; green for interpreting
dw lit, 0x200A, term_send
dw exit
;; (IP) -> W
;; IP + 1 -> IP
;; JP (W)
next:
mov r4, [r1]
add r1, 1
jmp r4
;; PUSH_IP_RS
;; POP IP
;; JP NEXT
docol:
sub r2, 1
mov [r2], r1
pop r1
jmp next
;; POP_IP_RS
;; JP NEXT
exit:
mov r1, [r2]
add r2, 1
jmp next
done_msg:
dw 0x200F, " ok", 0
interpret_done:
dw here, lit, var_here, store
dw lit, done_msg, puts
;; dw lit, str_buffer, lit, 128, erase
dw key, drop, main_asm
sz_link:
dw fetch_byte_link
dw 2, "s0 "
;; CODE
sz:
push r0
mov r0, [stack_zero]
jmp next
sp_fetch_link:
dw here_link
dw 3, "sp@"
sp_fetch:
push r0
mov r0, sp
jmp next
sp_store_link:
dw rp_fetch_link
dw 3, "sp!"
sp_store:
mov sp, r0
pop r0
jmp next
depth_link:
dw store_link
dw 5, "dep"
depth:
call docol
dw sz, sp_fetch, minus, two_minus, exit
print_stack_link:
dw allot_link
dw 2, ".s "
print_stack:
call docol
dw lit, '<', emit, depth, u_dot_, lit, '>', emit, space
dw sp_fetch
print_stack_loop:
dw dup, sz, one_minus, less_than
dw zjump, print_stack_done
dw dup, fetch, u_dot, one_plus
dw jump, print_stack_loop
print_stack_done:
dw drop, exit
not_found:
dw lit, word_buffer, puts
dw lit, not_found_msg, puts, halt
check_underflow:
cmp sp, [stack_zero_prog]
je report_underflow
jmp next
report_underflow:
mov r0, stack_underflow_msg
call write_string
hlt
jmp start
stack_underflow_msg:
dw 0x1000, 0x200C, "Stack underflow.", 0
welcome_msg:
dw 0x1000, 0x200E, "---R216 Forth---", 0
bytes_free_msg:
dw 0x200E, "cells left", 0
;; Word to be run on boot
welcome_proc:
call docol
dw lit, welcome_msg, puts
dw lit, 0x1010, term_send
dw lit, 0x200A, term_send
dw unused, d_dot, lit, bytes_free_msg, puts
dw exit
inputdata_prompt:
dw 0x1020, 0x200F, "> ", 0
dw 0
;; DATA
var_base:
dw 10
decimal_link:
dw qdup_link
dw 7, "dec"
decimal:
mov [var_base], 10
jmp next
hex_link:
dw rbrac_link
dw 3, "hex"
hex:
mov r4, 16
mov [var_base], r4
jmp next
latest_link:
dw puts_link
dw 6, "lat"
;; CODE
latest:
push r0
mov r0, var_latest
jmp next
base_link:
dw 0
dw 4, "bas"
;; CODE
base:
push r0
mov r0, var_base
jmp next
bool_xor_link:
dw drop_link
dw 3, "xor"
bool_xor:
pop r4
xor r0, r4
jmp next
bool_and_link:
dw if_link
dw 3, "and"
;; CODE
bool_and:
pop r4
and r0, r4
jmp next
;; strcmp:
;; pop r4
;; mov r5, [r0 + 0]
;; cmp r5, [r4 + 0]
;; jnz false
;; mov r5, [r0 + 1]
;; cmp r5, [r4 + 1]
;; jnz false
;; mov r5, [r0 + 2]
;; cmp r5, [r4 + 2]
;; jnz false
;; jmp true
;;; When adding words, append them to the linked list starting at .b00, then follow the advice of htcheck.lua:
;;;
;;; $ path/to/tptasm/main.lua model=R2... target=prog.bin export_labels=prog.labels prog.asm
;;; $ path/to/htcheck.lua prog.bin prog.labels
;;; star_link is in bucket 0x00, should be in bucket 0x16
;;;
;;; which would mean that star_link would have to be unlinked from .b00 and appended to .b16.
find_hashtable:
.b00: dw base_link
.b01: dw latest_link
.b02: dw plus_store_link
.b03: dw qimmed_link
.b04: dw fetch_link
.b05: dw depth_link
.b06: dw min_link
.b07: dw bool_and_link
.b08: dw comma_link
.b09: dw bool_xor_link
.b0A: dw store_byte_link
.b0B: dw sz_link
.b0C: dw create_link
.b0D: dw dup_link
.b0E: dw loop_index_two_link
.b0F: dw sp_fetch_link
.b10: dw rdrop_link
.b11: dw find_link
.b12: dw one_plus_link
.b13: dw to_link
.b14: dw one_minus_link
.b15: dw print_stack_link
.b16: dw unused_link
.b17: dw div_link
.b18: dw less_than_link
.b19: dw hex_link
.b1A: dw r_fetch_link
.b1B: dw nip_link
.b1C: dw do_loop_link
.b1D: dw div_mod_link
.b1E: dw decimal_link
.b1F: dw lbrac_link
;; Find a word
;; ( str_addr len -- xt | 0 )
;; CODE
find_link:
dw two_plus_link
dw 4, "fin"
find:
;; String length
mov r9, r0
pop r11
mov r4, r9
shl r4, 2
mov r5, .compare_0
sub r5, r9
cmp r9, 3
jb r5
xor r4, [r11 + 2]
xor r4, [r11 + 1]
xor r4, [r11 + 0]
;; the jb r5 jumps here or to one of the three xors above
;; or nowhere at all if r9 >= 3, thereby executing all three xors
.compare_0:
and r4, 0x1F
;; r4 points to the entry we're searching
;; Get the address of the latest word and skip the link
;; pointer.
mov r4, [r4+find_hashtable]
jz false
find_restart:
mov r5, r4
add r5, 1
mov r5, [r5]
;; Check if hidden.
ands r5, 64
;; Yes, skip it and continue traversing the linked list.
jnz find_loop
;; No, check length.
;; Remove flag data except for length.
and r5, 31
;; Same length?
cmp r5, r9
;; Yes, compare strings.
je find_cmp_string
;; No, continue searching.
jmp find_loop
find_cmp_string:
mov r7, r11
mov r6, r4
add r6, 2
;; r6 now points at the beginning of the name field
mov r8, [r6 + 0]
cmp r8, [r7 + 0]
jne find_loop
cmp r9, 1
je find_succ
mov r8, [r6 + 1]
cmp r8, [r7 + 1]
jne find_loop
cmp r9, 2
je find_succ
mov r8, [r6 + 2]
cmp r8, [r7 + 2]
jne find_loop
;; We found it!
find_succ:
mov r0, r4
jmp next
find_loop:
;; Deference the pointer
mov r4, [r4]
;; Hit null pointer.
jz false
jmp find_restart
allot_link:
dw swap_link
dw 5, "all"
;; CODE
allot:
add r3, r0
pop r0
jmp next
unused_link:
dw space_link
dw 6, "unu"
;; CODE
unused:
push r0
mov r4, r3
mov r0, [var_here_end]
sub r0, r4
jmp next
here_link:
dw rp_store_link
dw 4, "her"
;; CODE
here:
push r0
mov r0, r3
jmp next
;;; Aliases, since the R216 has 16-bit cells
fetch_byte_link:
dw to_cfa_link
dw 2, "c@ "
fetch_byte:
jmp fetch
store_byte_link:
dw mod_link
dw 2, "c! "
store_byte:
jmp store
fetch_link:
dw minus_store_link
dw 1, "@ "
;; CODE
fetch:
mov r4, [r0]
mov r0, r4
jmp next
store_link:
dw zero_equal_link
dw 1, "! "
;; CODE
store:
pop r4
mov [r0], r4
pop r0
jmp next
comma_link:
dw recurse_link
dw 1, ", "
comma:
mov [r3], r0
pop r0
add r3, 1
jmp next
plus_store_link:
dw qhidden_link
dw 2, "+! "
;; CODE
plus_store:
pop r4
add [r0], r4
pop r0
jmp next
minus_store_link:
dw to_r_link
dw 2, "-! "
;; CODE
minus_store:
pop r4
sub [r0], r4
pop r0
jmp next
;; unsigned divide r4 by r5 (doesn't handle division by 0)
;; quotient is r4, remainder is r6; clobbers r7 and r8
;; CODE
udiv1616:
mov r6, 0
mov r7, 0
mov r8, 16
.loop:
shl r7, 1
add r4, r4
adc r6, r6
jc .subtract_due_to_carry
cmp r6, r5
jnae .no_subtract
.subtract_due_to_carry:
sub r6, r5
or r7, 1
.no_subtract:
sub r8, 1
jnz .loop
mov r4, r7
ret
to_r_link:
dw r_from_link
dw 2, ">r "
to_r:
sub r2, 1
mov [r2], r0
pop r0
jmp next
r_from_link:
dw execute_link
dw 2, "r> "
r_from:
push r0
mov r0, [r2]
add r2, 1
jmp next
rp_store_link:
dw value_link
dw 3, "rp!"
rp_store:
mov r2, r0
pop r0
jmp next
r_fetch_link:
dw greater_than_link
dw 2, "r@ "
r_fetch:
push r0
mov r0, [r2]
jmp next
rp_fetch_link:
dw times_link
dw 3, "rp@"
rp_fetch:
push r0
mov r0, r2
jmp next
div_mod_link:
dw immed_link
dw 4, "/mo"
div_mod:
pop r4
mov r5, r0
call udiv1616
mov r0, r4
push r6
jmp next
left_shift:
add r0, r0
jmp next
right_shift:
shr r0, 1
jmp next
nip_link:
dw key_link
dw 3, "nip"
nip:
pop r4
jmp next
mod_link:
dw dot_link
dw 3, "mod"
mod:
call docol
dw div_mod, drop, exit
div_link:
dw two_minus_link
dw 3, "div"
div:
call docol
dw div_mod, nip, exit
space_link:
dw star_link
dw 5, "spa"
space:
send r10, 32
jmp next
u_dot_:
call docol
dw base, fetch, div_mod, qdup, zbranch, 2, u_dot_
dw dup, lit, 10, less_than, zbranch, 5, lit, '0'
dw branch, 6, lit, 10, minus, lit, 'A', plus
dw emit
dw exit
uwidth:
call docol
dw base, fetch, div, qdup, zbranch, 5, uwidth, one_plus
dw branch, 3, lit, 1, exit
;;; Writing instructions means that we have to access the full 29 bits
;;; Diagram of the situation:
;;; SWM (set write mask) takes the least 13 significant bits from the
;;; operand and sets the write mask to that
;;; SWM xxxnnnnnnnnnnnnn
;;; \-----------/
;;; |
;;; +-- [ part that gets written into the write mask ]
;;; Let's say DOCOL's address is 593 in base 10, then.
;;; The bits of the cell that corresponds to CALL DOCOL should look
;;; like this:
;;; 111110001000000010010100010000
;;; \------------/\--------------/
;;; | |
;;; [CALL opcode] +- [ address of DOCOL left shifted by 4 ]
;;; But here's the challenge: we can only write to the first 16 bits!
;;;
;;;
;;; [ the part SWM can write to ]
;;; |
;;; | +--- [ the part we can write to ]
;;; | |
;;; | |
;;; | |
;;; /------------\/--------------\
;;; 111110001000000010010100010000
;;; \------------/\--------------/
;;; | |
;;; [CALL opcode] +----- [ address of DOCOL ]
;;; If DOCOL's address is high enough we'll need to handle that, as
;;; a couple of its significant bits might end up in the SWM region,
;;; but to keep it simple let's make sure DOCOL is below 2^11
;; ( addr length -- )
;; Parse the next word and create a definition header for it.
create_asm:
;; Write the link pointer first
mov r4, [var_latest]
mov [r3], r4
mov [var_latest], r3
mov r4, docol
;; Main cell content
shl r4, 4
swm 15904
;; Write CALL DOCOL at offset 5
mov [r3 + 5], r4
;; Reset write mask
swm 0
;; Write the length
mov [r3 + 1], r0
pop r6
;; Write the first three characters of the name
mov r4, r0
shl r4, 2
mov r5, .write_0
sub r5, r0
sub r5, r0
sub r5, r0
cmp r0, 3
jb r5
mov r5, [r6 + 2]
xor r4, r5
mov [r3 + 4], r5
mov r5, [r6 + 1]
xor r4, r5
mov [r3 + 3], r5
mov r5, [r6]
xor r4, r5
mov [r3 + 2], r5
;; the jb r5 jumps here or to one of the three mov r5, [r6 + k]s above
;; or nowhere at all if r0 >= 3, thereby executing all three xors and moves
.write_0:
and r4, 0x1F
mov [r4+find_hashtable], r3
pop r0
add r3, 6
jmp next
create_link:
dw over_link
dw 6, "cre"
;; CODE
create:
call docol
dw word
;; DEBUG PRINT
dw lit, word_buffer, puts, space
dw create_asm, exit
immed_link:
dw hidden_link
dw 5, "imm"
;; CODE
immed:
mov r4, r0
mov r5, 128
xor [r4+1], r5
pop r0
jmp next
mov r4, 128
ands [r0], r4
jnz true
jz false
qimmed_link:
dw run_tick_link
dw 6, "?im"
;; CODE
qimmed:
mov r0, [r0+1]
ands r0, 128
jnz true
jz false
hidden_link:
dw divmod_link
dw 6, "hid"
;; CODE
hidden:
mov r4, r0
mov r5, 64
xor [r4+1], r5
pop r0
jmp next
qhidden_link:
dw constant_link
dw 7, "?hi"
;; CODE
qhidden:
mov r0, [r0+1]
ands r0, 64
jnz true
jz false
lbrac_link:
dw semicolon_link
dw 129, "[ "
;; IMMEDIATE CODE
lbrac:
mov [var_state], 0
jmp next
rbrac_link:
dw equal_link
dw 1, "] "
;; CODE
rbrac:
mov [var_state], 1
jmp next
constant_link:
dw d_dot_link
dw 8, "con"
;; CODE
constant:
jmp value
value_link:
dw plus_link
dw 5, "val"
;; WORD
value:
call docol
dw create, tick, lit, comma, comma, tick, exit, comma, exit
to_link:
dw u_dot_link
dw 130, "to "
;; IMMEDIATE WORD
to:
call docol
dw word, find, to_dfa, one_plus, state, fetch
dw zbranch, 10, tick, lit, comma, comma
dw tick, store, comma, branch, 2, store, exit
dot_link:
dw not_equal_link
dw 1, ". "
;; CODE
dot:
jmp d_dot
;;; Much faster than U. but only for base 10.
d_dot_link:
dw erase_link
dw 2, "d. "
;; CODE
d_dot:
;;; Written by LBPHacker
;;; unsigned render r4 into zero-terminated bcd
;;; r5 is set to point to result (owned by the subroutine, don't write to it)
;;; clobbers r4, r6, r7 and r8
tozstringu16:
mov r4, r0
test r4, r4
jz .r4_zero
mov r5, 0
mov r6, 0
mov r7, 16
.loop:
shl r4, 1
scl r5, 1
scl r6, 1
sub r7, 1
jz .loop_done
mov r8, r5
ror r5, 1
or r8, r5
ror r5, 1
and r8, r5
ror r5, 1
or r8, r5
rol r5, 3
and r8, 0x1111
add r5, r8
add r5, r8
add r5, r8
jmp .loop
.loop_done:
mov r7, .output_4
mov [r7], r5
and [r7], 15
add [r7], '0'
shr r5, 4
sub r7, 1
mov [r7], r5
and [r7], 15
add [r7], '0'
shr r5, 4
sub r7, 1
mov [r7], r5
and [r7], 15
add [r7], '0'
shr r5, 4
add r5, '0'
sub r7, 1
mov [r7], r5
add r6, '0'
sub r7, 1
mov [r7], r6
mov r5, r7
.find_head:
cmp [r5], '0'
jne .done
add r5, 1
jmp .find_head
.done:
jmp print_d_dot
.r4_zero:
mov r5, .output_0
add r5, 4
mov [r5], '0'
jmp print_d_dot
.output_0: dw 0
.output_1: dw 0
.output_2: dw 0
.output_3: dw 0
.output_4: dw 0
.output_z: dw 0
print_d_dot:
mov r0, r5
call write_string
;; Space at the end
send r10, 32
pop r0
jmp next
u_dot_link:
dw two_dup_link
dw 2, "u. "
;; WORD
u_dot:
call docol
dw u_dot_, space, exit
qdup_link:
dw zero_not_equal_link
dw 4, "?du"
;; CODE
qdup:
cmp r0, 0
je next
push r0
jmp next
true:
mov r0, 1
jmp next
false:
mov r0, 0
jmp next
less_than_link:
dw max_link
dw 1, "< "
;; CODE
less_than:
pop r4
cmp r4, r0
jl true
jmp false
greater_than_link:
dw word_link
dw 1, "> "
;; CODE
greater_than:
pop r4
cmp r4, r0
jg true
jmp false
equal_link:
dw not_link
dw 1, "= "
;; CODE
equal:
pop r4
cmp r4, r0
je true
jmp false
zero_not_equal_link:
dw double_times_link
dw 3, "0<>"
;; CODE
zero_not_equal: