-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathmul.in
49 lines (40 loc) · 885 Bytes
/
mul.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
#
# About
#
# This program multiples and divides two numbers.
#
#
# Usage
#
# $ compiler ./mul.in ; ./simple-vm ./mul.raw
#
#
#
store #1, 10
store #2, 20
# show what we'll do
store #5, "Multiplying "
print_str #5
print_int #1
store #5, " and "
print_str #5
print_int #2
store #5, "\n"
print_str #5
# carry out the muiltiplication
mul #0, #1, #2
# show the result
store #5, "Result: "
print_str #5
print_int #0
store #5, "\n"
print_str #5
# now try a division. #0 will have 200. Divide by 4.
store #5, "Now dividing that result by four:\n"
print_str #5
store #3, 4
div #0, #0, #3
print_int #0
# add newline to the output
store #1, "\n"
print_str #1