/ test / asm / fibonacci_mem.asm
fibonacci_mem.asm
 1  # Data adress space:
 2  # 0x0 - fn-2
 3  # 0x4 - fn-1
 4  # 0x8 - target
 5  clearDataMem:
 6      sb x0, 0(x0)
 7      sb x0, 4(x0)
 8  initMem:
 9      li x2, 1
10      sb x2, 4(x0)
11      li x2, 55 # fib(10)
12      sw x2, 8(x0)
13  loop:
14      # collect data from memory
15      lw x1, 0(x0)
16      lw x2, 4(x0)
17      # generate next fibonacci number
18      add x3, x2, x1
19      # store data in memory
20      sw x2, 0(x0)
21      sw x3, 4(x0)
22      # compare with expected result
23      lw x4, 8(x0)
24      bne x3, x4, loop
25  infloop:
26      j infloop
27  
28  .section .bss
29  .skip 0xC