diff options
| author | Julian Blake Kongslie | 2021-04-04 16:20:24 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2021-04-04 16:20:24 -0700 |
| commit | 6a031fb49d595726da16adcf868475b1e104d60d (patch) | |
| tree | 354dc4ca0978261b804533f91cf9298937c0a4ee /mem | |
| parent | Add indirect memory operations. (diff) | |
| download | noncpu-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.hex | 154 |
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 | 3 | 10d // acc= @fib # for the toy indirect jump to fib |
| 4 | 369 // store 0x69 | ||
| 5 | 170 // acc= 0x70 | ||
| 6 | 36a // store 0x6a | ||
| 7 | 001 // loop: cla | ||
| 8 | 2ea // ladd i 0x6a | ||
| 9 | 400 // ifeq 0 | ||
| 10 | 5e9 // jmp i 0x69 # toy indirect jump to fib | ||
| 11 | 040 // tx | ||
| 12 | 003 // cla ++acc | ||
| 13 | 26a // ladd 0x6a | ||
| 14 | 36a // store 0x6a | ||
| 15 | 577 // jmp loop | ||
| 16 | 36a // fib: store 0x6a # zero, it is known | ||
| 17 | 370 // store 0x70 # 0x70 is now beginning of Fibonacci sequence (0) | ||
| 18 | 003 // cla ++acc | ||
| 19 | 371 // store 0x71 # 0x71 is 1 | ||
| 20 | 170 // fibloop: acc= 0x70 | ||
| 21 | 26a // ladd 0x6a | ||
| 22 | 369 // store 0x69 | ||
| 23 | 001 // cla | ||
| 24 | 2e9 // ladd i 0x69 # next fib number to print | ||
| 25 | 66b // ascii 0x6b # LSB of ASCII rep | ||
| 26 | 66c // ascii 0x6c | ||
| 27 | 66d // ascii 0x6d | ||
| 28 | 66e // ascii 0x6e # MSB of ASCII rep | ||
| 29 | 104 // acc= 4 | ||
| 30 | 369 // store 0x69 | ||
| 31 | 005 // scan: cla --acc | ||
| 32 | 269 // ladd 0x69 | ||
| 33 | 4ff // ifeq -1 | ||
| 34 | 508 // jmp print | ||
| 35 | 369 // store 0x69 | ||
| 36 | 16b // acc= 0x6b | ||
| 37 | 269 // ladd 0x69 | ||
| 38 | 368 // store 0x68 | ||
| 39 | 001 // cla | ||
| 40 | 2e8 // ladd i 0x68 | ||
| 41 | 430 // ifeq 0x30 | ||
| 42 | 574 // jmp scan | ||
| 43 | 16b // print: acc= 0x6b | ||
| 44 | 269 // ladd 0x69 | ||
| 45 | 368 // store 0x68 | ||
| 46 | 001 // cla | ||
| 47 | 2e8 // ladd i 0x68 | ||
| 48 | 040 // tx | ||
| 49 | 005 // cla --acc | ||
| 50 | 269 // ladd 0x69 | ||
| 51 | 4ff // ifeq -1 | ||
| 52 | 502 // jmp space | ||
| 53 | 369 // store 0x69 | ||
| 54 | 574 // jmp print | ||
| 55 | 120 // space: acc= 0x20 | ||
| 56 | 040 // tx | ||
| 57 | 170 // acc= 0x70 | ||
| 58 | 26a // ladd 0x6a | ||
| 59 | 369 // store 0x69 | ||
| 60 | 003 // cla ++acc | ||
| 61 | 269 // ladd 0x69 # compute &fib[i+1] | ||
| 62 | 368 // store 0x68 | ||
| 63 | 003 // cla ++acc | ||
| 64 | 268 // ladd 0x68 # compute &fib[i+2] | ||
| 65 | 367 // store 0x67 | ||
| 66 | 001 // cla | ||
| 67 | 2e9 // ladd i 0x69 | ||
| 68 | 2e8 // ladd i 0x68 # compute fib[i+2] | ||
| 69 | 3e7 // store i 0x67 # store it | ||
| 70 | 003 // cla ++acc | ||
| 71 | 26a // ladd 0x6a | ||
| 72 | 432 // ifeq 50 | ||
| 73 | 502 // jmp fullydone | ||
| 74 | 36a // store 0x6a | ||
| 75 | 548 // jmp fibloop | ||
| 76 | 121 // fullydone: acc= 0x21 | ||
| 77 | 040 // tx | ||
| 78 | 080 // halt | ||
| 4 | 79 | ||
| 5 | 000 // loop: acc= 0 # Print from 0x70 until we find a 0x00 byte | 80 | // 67: scratch (pointer to fib[i+2]) |
| 6 | 170 // ladd i 0x6a | 81 | // 68: scratch (pointer to fib[i+1]) |
| 7 | 300 // ifeq 0 | 82 | // 69: scratch (pointer to fib[i]) (j) |
| 8 | 402 // jmp fib | 83 | // 6a: i |
| 9 | f44 // ++idx tx | 84 | // 6b: LSB of ASCII rep |
| 10 | 4fa // jmp loop | 85 | // 6c: USB of ASCII rep |
| 11 | f20 // fib: idx # N.B. acc is 0 at this point (we got here from ifeq 0) | 86 | // 6d: USB of ASCII rep |
| 12 | 270 // store 0x70 # 0x70 is now beginning of Fibonacci sequence (0) | 87 | // 6e: MSB of ASCII rep |
| 13 | 001 // acc= 1 | ||
| 14 | 271 // store 0x71 # 0x71 is 1 | ||
| 15 | 000 // fibloop: acc= 0 | ||
| 16 | f10 // swap | ||
| 17 | 332 // ifeq 50 | ||
| 18 | 42b // jmp fullydone | ||
| 19 | 26f // store 0x6f # 0x6f is current index into Fibonacci sequence | ||
| 20 | f10 // swap | ||
| 21 | 170 // ladd 0x70 # Load next unprinted number in Fibonacci sequence | ||
| 22 | f10 // swap | ||
| 23 | 000 // acc= 0 | ||
| 24 | f10 // swap | ||
| 25 | 56b // ascii 0x6b # LSB of ASCII rep | ||
| 26 | 56c // ascii 0x6c | ||
| 27 | 56d // ascii 0x6d | ||
| 28 | 56e // ascii 0x6e # MSB of ASCII rep | ||
| 29 | 004 // acc= 4 | ||
| 30 | f10 // swap | ||
| 31 | f08 // scan: --idx | ||
| 32 | 000 // acc= 0 | ||
| 33 | 16b // ladd 0x6b | ||
| 34 | f10 // swap | ||
| 35 | 300 // ifeq 0 | ||
| 36 | 412 // jmp allzeroes | ||
| 37 | f10 // swap | ||
| 38 | 330 // ifeq 0x30 | ||
| 39 | 4f7 // jmp scan | ||
| 40 | f40 // done: tx | ||
| 41 | f10 // swap | ||
| 42 | 300 // ifeq 0 | ||
| 43 | 404 // jmp space | ||
| 44 | f12 // --acc swap | ||
| 45 | 000 // acc= 0 | ||
| 46 | 16b // ladd 0x6b | ||
| 47 | 4f8 // jmp done | ||
| 48 | 020 // space: acc= 0x20 | ||
| 49 | f40 // tx | ||
| 50 | 000 // acc= 0 | ||
| 51 | f20 // idx | ||
| 52 | 16f // ladd 0x6f | ||
| 53 | f10 // swap | ||
| 54 | 402 // jmp nextfib | ||
| 55 | f10 // allzeroes: swap | ||
| 56 | 4ef // jmp done | ||
| 57 | 170 // nextfib: ladd 0x70 # Load just-printed Fibonacci number | ||
| 58 | 171 // ladd 0x71 # Add about-to-print Fibonacci number | ||
| 59 | 272 // store 0x72 # Store n+2 Fibonacci number | ||
| 60 | f04 // ++idx | ||
| 61 | 4d1 // jmp fibloop | ||
| 62 | 021 // fullydone: acc= 0x21 | ||
| 63 | f40 // tx | ||
| 64 | f80 // halt | ||
| 65 | |||
| 66 | @6a | ||
| 67 | |||
| 68 | 070 // 6a: constant 0x070 | ||
| 69 | 000 // 6b: LSB of ASCII rep | ||
| 70 | 000 // 6c: USB of ASCII rep | ||
| 71 | 000 // 6d: USB of ASCII rep | ||
| 72 | 000 // 6e: MSB of ASCII rep | ||
| 73 | 000 // 6f: next index to store in memory image of Fibonacci sequence | ||
| 74 | 88 | ||
| 75 | @70 | 89 | @70 |
| 76 | 90 | ||
