diff options
Diffstat (limited to 'mem')
| -rw-r--r-- | mem/mem.hex | 78 |
1 files changed, 66 insertions, 12 deletions
diff --git a/mem/mem.hex b/mem/mem.hex index 63038e3..d30c5b6 100644 --- a/mem/mem.hex +++ b/mem/mem.hex | |||
| @@ -1,25 +1,79 @@ | |||
| 1 | @0 | 1 | @0 |
| 2 | 2 | ||
| 3 | 000 // loop: acc= 0 | 3 | // Reset state is acc=0 idx=0 |
| 4 | 140 // load 0x40 | 4 | |
| 5 | 000 // loop: acc= 0 # Print from 0x70 until we find a 0x00 byte | ||
| 6 | 170 // ladd 0x70 | ||
| 5 | 300 // ifeq 0 | 7 | 300 // ifeq 0 |
| 6 | 402 // jmp fib | 8 | 402 // jmp fib |
| 7 | f44 // ++idx tx | 9 | f44 // ++idx tx |
| 8 | 4fa // jmp loop | 10 | 4fa // jmp loop |
| 9 | f20 // fib: idx | 11 | f20 // fib: idx # N.B. acc is 0 at this point (we got here from ifeq 0) |
| 10 | 240 // store 0x40 | 12 | 270 // store 0x70 # 0x70 is now beginning of Fibonacci sequence (0) |
| 11 | 001 // acc= 1 | 13 | 001 // acc= 1 |
| 12 | 241 // store 0x41 | 14 | 271 // store 0x71 # 0x71 is 1 |
| 13 | 000 // fibloop: acc= 0 | 15 | 000 // fibloop: acc= 0 |
| 14 | 140 // load 0x40 | 16 | f10 // swap |
| 15 | f44 // tx ++idx | 17 | 332 // ifeq 50 |
| 16 | 140 // load 0x40 | 18 | 42b // jmp fullydone |
| 17 | 241 // store 0x41 | 19 | 26f // store 0x6f # 0x6f is current index into Fibonacci sequence |
| 18 | 4fa // jmp fibloop | 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 | @6c | ||
| 67 | |||
| 68 | 000 // 6b: LSB of ASCII rep | ||
| 69 | 000 // 6c: USB of ASCII rep | ||
| 70 | 000 // 6d: USB of ASCII rep | ||
| 71 | 000 // 6e: MSB of ASCII rep | ||
| 72 | 000 // 6f: next index to store in memory image of Fibonacci sequence | ||
| 19 | 73 | ||
| 20 | @40 | 74 | @70 |
| 21 | 75 | ||
| 22 | 048 // H | 76 | 048 // H # later: start of in-memory Fib sequence |
| 23 | 065 // e | 77 | 065 // e |
| 24 | 06c // l | 78 | 06c // l |
| 25 | 06c // l | 79 | 06c // l |
