forked from skx/go.vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compare.in
50 lines (40 loc) · 817 Bytes
/
compare.in
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
#
# About
#
# This program compares the number in a register with a constant.
#
# Usage:
#
# $ go.vm run ./compare.in
#
# Or compile, then execute:
#
# $ go.vm compile ./compare.in
# $ go.vm execute ./compare.raw
#
store #1, 44
cmp #1, 44
jmpz equal
store #1, "Inequal\n"
print_str #1
exit
:equal
store #1, "EQUAL\n"
print_str #1
store #1, "Steve"
cmp #1, "Kemp"
jmpnz str1
store #1, "Eek string 1 compare failed - BUG?\n"
print_str #1
exit
:str1
store #1, "Steve"
cmp #1, "Steve"
jmpz str2
store #1, "Eek string 2 compare failed - BUG?\n"
print_str #1
exit
:str2
store #1, "String comparisions OK\n"
print_str #1
exit