.data .org 0x10 list: .fill 0x1 ;1. element = 1 ;0x10 .fill 0x1 ;2. element = 1 ;0x14 .fill 0x100, 0x0 ;nullen.. .text main: ldi r1, 9; ldil r10, list@lo ; global pointer ldih r10, list@hi call+ fibcall; br+ main; ; fib(n) { ; if (list[n] > 0) { ; return list[n] ; } ; a = fib(n-1) ; list[n] = a + list[n-2] ; return list[n] ; } fibcall: ;update counter for aligned access lls r1, r1, 2 ; *4 ;calculate adress of top element add r2, r10, r1 fibmem: ;load top element ldw r0, 0(r2) ;compare if set cmpi r0, 0 ;return if set retnz- ;decrement adress for next lopp subi r2, r2, 4 ;iterative call for n-1 element call+ fibmem ;load n-2 element ldw r3, 0-4(r2) ;add n-1 and n-2 element add r0, r3, r0 ;increment address for n element ;is needed because after return ;we need r2 to be set to the address ;of element n addi r2, r2, 4 ;store fib n stw r0, 0(r2) ret+