forked from skx/go.vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.in
53 lines (43 loc) · 867 Bytes
/
math.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
51
52
53
#
# About
#
# This program demonstrates the use of bitwise AND and XOR operations.
#
# Usage:
#
# $ go.vm run ./math.in
#
# Or compile, then execute:
#
# $ go.vm compile ./math.in
# $ go.vm execute ./math.raw
#
store #1, "255 & 16 is : "
print_str #1
store #1, 255
store #2, 16
and #0, #1, #2
print_int #0
store #1, "\n"
print_str #1
cmp #0, 16
jmpz and_ok
store #1, "Result is WRONG!\n"
print_str #1
exit
:and_ok
store #1, "32 XOR 23 is : "
print_str #1
# 32 XOR 23 => 55
store #1, 32
store #2, 23
xor #0, #1, #2
print_int #0
store #1, "\n"
print_str #1
cmp #0, 55
jmpz xor_ok
store #1, "Result is WRONG!\n"
print_str #1
exit
:xor_ok