; fib.asm. Compute Fibonnaci numbers cnt: .equ 5 ; # to compute after first two .org 0 ; store next line to address 0 seq: .dc 1 ; initialize Fib(n-2) # next: .dc 1 ; initialize second Fib(n-1) # ans: .dw cnt ; reserve space for cnt Fib numbers .org 0x1000 ; Begin at hex address 1000 lar r31, loop ; save address of loop into r31 la r0, cnt ; initialize count, r0=M[cnt], how many iterations? la r1, seq ; Init r1 = seq[0] - base address of seq loop: ld r2, seq(r1) ; load Fib(n-2) to r2 ld r3, next(r1) ; load Fib(n-1) to r3 add r2, r2, r3 ; compute r2+r3 put result in r2( fib(n-2)+fib(n-1)) st r2, ans(r1) ; store result in ans[i] addi r1, r1, 4 ; increment index addi r0, r0, -1 ; decrement count brnz r31, r0 ; loop until done -- branch to r31 (loop) if r31 isn't 0 stop #define cnt 5 int seq = 1; int next = 1; int ans[cnt]; register int r0 = cnt; register int r1 = seq; register int r2 = seq[r1]; register int r3