forked from skx/simple.vm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop.in
More file actions
41 lines (33 loc) · 663 Bytes
/
loop.in
File metadata and controls
41 lines (33 loc) · 663 Bytes
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
#
# About
#
# Use a conditional jump to loop ten times, the conditional will trigger
# if a "SUB" operation results in <0.
#
#
# Usage
#
# $ compiler ./loop.in ; ./simple-vm ./loop.raw
#
#
#
store #1, "Counting from ten to zero\n"
print_str #1
store #1, 11
store #2, 1
:repeat
#
# This means "reg1 = reg1 - reg2"
#
sub #1, #1, #2
print_int #1
# 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\n"
print_str #1
exit