forked from skx/go.vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
concat.in
47 lines (37 loc) · 759 Bytes
/
concat.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
#
# About
#
# Use a conditional jump to loop ten times, building up a string as we go.
#
# Usage:
#
# $ go.vm run ./concat.in
#
# Or compile, then execute:
#
# $ go.vm compile ./concat.in
# $ go.vm execute ./concat.raw
#
store #1, "Counting bananas"
print_str #1
store #1, 10
store #2, 1
store #3, ""
store #4, " banana"
:repeat
#
# This means "reg1 = reg1 - reg2"
#
sub #1, #1, #2
concat #3, #3, #4
print_str #3
# add newline to the output
store #5, "\n"
print_str #5
#
# This jump only occur if the zero-flag is set.
#
jmpnz repeat
store #1, "Done"
print_str #1
exit