summaryrefslogtreecommitdiff
path: root/mem
diff options
context:
space:
mode:
authorJulian Blake Kongslie2021-04-04 16:20:24 -0700
committerJulian Blake Kongslie2021-04-04 16:20:24 -0700
commit6a031fb49d595726da16adcf868475b1e104d60d (patch)
tree354dc4ca0978261b804533f91cf9298937c0a4ee /mem
parentAdd indirect memory operations. (diff)
downloadnoncpu-6a031fb49d595726da16adcf868475b1e104d60d.tar.xz
Remove idx, add indirect jumps, renumber opcodes so NOP=0, add absolute labels to asm.rb
Diffstat (limited to 'mem')
-rw-r--r--mem/mem.hex154
1 files changed, 84 insertions, 70 deletions
diff --git a/mem/mem.hex b/mem/mem.hex
index 07023a8..4d5700f 100644
--- a/mem/mem.hex
+++ b/mem/mem.hex
@@ -1,76 +1,90 @@
1@0 1@0
2 2
3// Reset state is acc=0 idx=0 310d // acc= @fib # for the toy indirect jump to fib
4369 // store 0x69
5170 // acc= 0x70
636a // store 0x6a
7001 // loop: cla
82ea // ladd i 0x6a
9400 // ifeq 0
105e9 // jmp i 0x69 # toy indirect jump to fib
11040 // tx
12003 // cla ++acc
1326a // ladd 0x6a
1436a // store 0x6a
15577 // jmp loop
1636a // fib: store 0x6a # zero, it is known
17370 // store 0x70 # 0x70 is now beginning of Fibonacci sequence (0)
18003 // cla ++acc
19371 // store 0x71 # 0x71 is 1
20170 // fibloop: acc= 0x70
2126a // ladd 0x6a
22369 // store 0x69
23001 // cla
242e9 // ladd i 0x69 # next fib number to print
2566b // ascii 0x6b # LSB of ASCII rep
2666c // ascii 0x6c
2766d // ascii 0x6d
2866e // ascii 0x6e # MSB of ASCII rep
29104 // acc= 4
30369 // store 0x69
31005 // scan: cla --acc
32269 // ladd 0x69
334ff // ifeq -1
34508 // jmp print
35369 // store 0x69
3616b // acc= 0x6b
37269 // ladd 0x69
38368 // store 0x68
39001 // cla
402e8 // ladd i 0x68
41430 // ifeq 0x30
42574 // jmp scan
4316b // print: acc= 0x6b
44269 // ladd 0x69
45368 // store 0x68
46001 // cla
472e8 // ladd i 0x68
48040 // tx
49005 // cla --acc
50269 // ladd 0x69
514ff // ifeq -1
52502 // jmp space
53369 // store 0x69
54574 // jmp print
55120 // space: acc= 0x20
56040 // tx
57170 // acc= 0x70
5826a // ladd 0x6a
59369 // store 0x69
60003 // cla ++acc
61269 // ladd 0x69 # compute &fib[i+1]
62368 // store 0x68
63003 // cla ++acc
64268 // ladd 0x68 # compute &fib[i+2]
65367 // store 0x67
66001 // cla
672e9 // ladd i 0x69
682e8 // ladd i 0x68 # compute fib[i+2]
693e7 // store i 0x67 # store it
70003 // cla ++acc
7126a // ladd 0x6a
72432 // ifeq 50
73502 // jmp fullydone
7436a // store 0x6a
75548 // jmp fibloop
76121 // fullydone: acc= 0x21
77040 // tx
78080 // halt
4 79
5000 // loop: acc= 0 # Print from 0x70 until we find a 0x00 byte 80// 67: scratch (pointer to fib[i+2])
6170 // ladd i 0x6a 81// 68: scratch (pointer to fib[i+1])
7300 // ifeq 0 82// 69: scratch (pointer to fib[i]) (j)
8402 // jmp fib 83// 6a: i
9f44 // ++idx tx 84// 6b: LSB of ASCII rep
104fa // jmp loop 85// 6c: USB of ASCII rep
11f20 // fib: idx # N.B. acc is 0 at this point (we got here from ifeq 0) 86// 6d: USB of ASCII rep
12270 // store 0x70 # 0x70 is now beginning of Fibonacci sequence (0) 87// 6e: MSB of ASCII rep
13001 // acc= 1
14271 // store 0x71 # 0x71 is 1
15000 // fibloop: acc= 0
16f10 // swap
17332 // ifeq 50
1842b // jmp fullydone
1926f // store 0x6f # 0x6f is current index into Fibonacci sequence
20f10 // swap
21170 // ladd 0x70 # Load next unprinted number in Fibonacci sequence
22f10 // swap
23000 // acc= 0
24f10 // swap
2556b // ascii 0x6b # LSB of ASCII rep
2656c // ascii 0x6c
2756d // ascii 0x6d
2856e // ascii 0x6e # MSB of ASCII rep
29004 // acc= 4
30f10 // swap
31f08 // scan: --idx
32000 // acc= 0
3316b // ladd 0x6b
34f10 // swap
35300 // ifeq 0
36412 // jmp allzeroes
37f10 // swap
38330 // ifeq 0x30
394f7 // jmp scan
40f40 // done: tx
41f10 // swap
42300 // ifeq 0
43404 // jmp space
44f12 // --acc swap
45000 // acc= 0
4616b // ladd 0x6b
474f8 // jmp done
48020 // space: acc= 0x20
49f40 // tx
50000 // acc= 0
51f20 // idx
5216f // ladd 0x6f
53f10 // swap
54402 // jmp nextfib
55f10 // allzeroes: swap
564ef // jmp done
57170 // nextfib: ladd 0x70 # Load just-printed Fibonacci number
58171 // ladd 0x71 # Add about-to-print Fibonacci number
59272 // store 0x72 # Store n+2 Fibonacci number
60f04 // ++idx
614d1 // jmp fibloop
62021 // fullydone: acc= 0x21
63f40 // tx
64f80 // halt
65
66@6a
67
68070 // 6a: constant 0x070
69000 // 6b: LSB of ASCII rep
70000 // 6c: USB of ASCII rep
71000 // 6d: USB of ASCII rep
72000 // 6e: MSB of ASCII rep
73000 // 6f: next index to store in memory image of Fibonacci sequence
74 88
75@70 89@70
76 90