forked from skx/simple.vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quine.in
81 lines (70 loc) · 1.38 KB
/
quine.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#
# About
#
# Show the binary opcodes of this program!
#
#
# Usage
#
# $ compiler ./quine.in ; ./simple-vm ./quine.raw
#
#
#
#
# The number of bytes to show is the same as the length
# of this (compiled) script.
#
# If we store the offset of the "end" label, in register 1,
# that will correspond to our length.
#
store #1, end
#
# We'll loop with offset 1.
#
# i.e. register 1 is the store of iterates.
#
# and each loop we set: reg1 = reg1 - reg2
#
#
store #2, 1
#
# Address to show
#
store #3, 0
:repeat
#
# Print a prefix for the bytes.
#
store #5, "0x"
print_str #5
#
# Get the contents of the byte and show it
#
peek #5, #3
print_int #5
#
# Increase to show the next address.
#
inc #3
#
# Show some spacing.
#
store #5, " "
print_str #5
#
# Loop until we're done.
#
sub #1, #1, #2
jmpnz repeat
#
# Terminate with a newline.
#
store #1, "\n"
print_str #1
exit
#
# DATA - just for fun.
#
DB 0x01, 0x0F, 0x02, 0xF0
DATA 255, 255
:end