From 6d3551cb8b754897a42ee264135122b80a122be1 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Mon, 5 Apr 2021 13:24:52 -0700 Subject: Use the assembler for allocating static storage in the Fib program. --- mem/mem.hex | 102 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/mem/mem.hex b/mem/mem.hex index 4d5700f..a0c98e5 100644 --- a/mem/mem.hex +++ b/mem/mem.hex @@ -1,94 +1,94 @@ @0 -10d // acc= @fib # for the toy indirect jump to fib -369 // store 0x69 +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 -36a // store 0x6a +301 // store @i 001 // loop: cla -2ea // ladd i 0x6a +281 // ladd i @i 400 // ifeq 0 -5e9 // jmp i 0x69 # toy indirect jump to fib +586 // jmp i @fib0 # toy indirect jump to fib 040 // tx 003 // cla ++acc -26a // ladd 0x6a -36a // store 0x6a +201 // ladd @i +301 // store @i 577 // jmp loop -36a // fib: store 0x6a # zero, it is known -370 // store 0x70 # 0x70 is now beginning of Fibonacci sequence (0) +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 +371 // store 0x71 # 0x71 is 1 170 // fibloop: acc= 0x70 -26a // ladd 0x6a -369 // store 0x69 +201 // ladd @i +306 // store @fib0 001 // cla -2e9 // ladd i 0x69 # next fib number to print -66b // ascii 0x6b # LSB of ASCII rep -66c // ascii 0x6c -66d // ascii 0x6d -66e // ascii 0x6e # MSB of ASCII rep +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 -369 // store 0x69 +306 // store @j 005 // scan: cla --acc -269 // ladd 0x69 +206 // ladd @j 4ff // ifeq -1 508 // jmp print -369 // store 0x69 -16b // acc= 0x6b -269 // ladd 0x69 -368 // store 0x68 +306 // store @j +102 // acc= @ascii0 +206 // ladd @j +307 // store @x 001 // cla -2e8 // ladd i 0x68 +287 // ladd i @x 430 // ifeq 0x30 574 // jmp scan -16b // print: acc= 0x6b -269 // ladd 0x69 -368 // store 0x68 +102 // print: acc= @ascii0 +206 // ladd @j +307 // store @x 001 // cla -2e8 // ladd i 0x68 +287 // ladd i @x 040 // tx 005 // cla --acc -269 // ladd 0x69 +206 // ladd @j 4ff // ifeq -1 502 // jmp space -369 // store 0x69 +306 // store @j 574 // jmp print 120 // space: acc= 0x20 040 // tx 170 // acc= 0x70 -26a // ladd 0x6a -369 // store 0x69 +201 // ladd @i +306 // store @fib0 003 // cla ++acc -269 // ladd 0x69 # compute &fib[i+1] -368 // store 0x68 +206 // ladd @fib0 # compute &fib[i+1] +307 // store @fib1 003 // cla ++acc -268 // ladd 0x68 # compute &fib[i+2] -367 // store 0x67 +207 // ladd @fib1 # compute &fib[i+2] +308 // store @fib2 001 // cla -2e9 // ladd i 0x69 -2e8 // ladd i 0x68 # compute fib[i+2] -3e7 // store i 0x67 # store it +286 // ladd i @fib0 +287 // ladd i @fib1 # compute fib[i+2] +388 // store i @fib2 # store it 003 // cla ++acc -26a // ladd 0x6a +201 // ladd @i 432 // ifeq 50 502 // jmp fullydone -36a // store 0x6a +301 // store @i 548 // jmp fibloop 121 // fullydone: acc= 0x21 040 // tx 080 // halt -// 67: scratch (pointer to fib[i+2]) -// 68: scratch (pointer to fib[i+1]) -// 69: scratch (pointer to fib[i]) (j) -// 6a: i -// 6b: LSB of ASCII rep -// 6c: USB of ASCII rep -// 6d: USB of ASCII rep -// 6e: MSB of ASCII rep - @70 -048 // H # later: start of in-memory Fib sequence +048 // H # later: start of in-memory Fib sequence 065 // e 06c // l 06c // l -- cgit v1.2.3