summaryrefslogtreecommitdiff
path: root/mem/mem.hex
blob: 84caf6d209d795b1ea2fae8b8721f2b17c42e53f (plain) (blame)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
@0

508 // jmp start
000 // i: 0                 # outer loop index
000 // ascii0: 0            # ascii digits must be in consecutive incrementing addresses
000 // ascii1: 0
000 // ascii2: 0
000 // ascii3: 0
000 // fib0: j: 0           # fib[n]; clobbered by ascii printer for inner loop index
000 // fib1: x: 0           # fib[n+1]; clobbered by ascii printer for digit being printed
000 // fib2: 0              # fib[n+2]
116 // start: acc= @fib     # for the toy indirect jump to fib
306 // store @fib0
170 // acc= 0x70
301 // store @i
001 // loop: cla
281 // ladd i @i
400 // ifeq 0
586 // jmp i @fib0          # toy indirect jump to fib
040 // tx
003 // cla ++acc
201 // ladd @i
301 // store @i
577 // jmp loop
301 // fib: store @i        # zero, it is known
370 // store 0x70           # 0x70 is now beginning of Fibonacci sequence (0)
003 // cla ++acc
371 // store 0x71           # 0x71 is 1
170 // fibloop: acc= 0x70
201 // ladd @i
306 // store @fib0
001 // cla
286 // ladd i @fib0         # next fib number to print
602 // ascii @ascii0        # LSB of ASCII rep
603 // ascii @ascii1
604 // ascii @ascii2
605 // ascii @ascii3        # MSB of ASCII rep
104 // acc= 4
306 // store @j
005 // scan: cla --acc
206 // ladd @j
4ff // ifeq -1
508 // jmp print
306 // store @j
102 // acc= @ascii0
206 // ladd @j
307 // store @x
001 // cla
287 // ladd i @x
430 // ifeq 0x30
574 // jmp scan
102 // print: acc= @ascii0
206 // ladd @j
307 // store @x
001 // cla
287 // ladd i @x
040 // tx
005 // cla --acc
206 // ladd @j
4ff // ifeq -1
502 // jmp space
306 // store @j
574 // jmp print
120 // space: acc= 0x20
040 // tx
170 // acc= 0x70
201 // ladd @i
306 // store @fib0
003 // cla ++acc
206 // ladd @fib0           # compute &fib[i+1]
307 // store @fib1
003 // cla ++acc
207 // ladd @fib1           # compute &fib[i+2]
308 // store @fib2
001 // cla
286 // ladd i @fib0
287 // ladd i @fib1         # compute fib[i+2]
388 // store i @fib2        # store it
003 // cla ++acc
201 // ladd @i
432 // ifeq 50
502 // jmp fullydone
301 // store @i
548 // jmp fibloop
121 // fullydone: acc= 0x21
040 // tx
000 // halt

@70

048 // H                    # later: start of in-memory Fib sequence
065 // e
06c // l
06c // l
06f // o
02c // ,
020 // ' '
077 // w
06f // o
072 // r
06c // l
064 // d
021 // !
00a // \n

000