#include "dt_inc.s" .data .org 0x0 list: .fill 0x1 ;1. element = 1 ;0x10 .fill 0x1 ;2. element = 1 ;0x14 .fill 0x10, 0x0 ;nullen.. str: .ascii "hier das ergebnis: " .text .org 0x0 start: br+ main br+ main ret main: call+ u_init call+ u_recv_byte call u_send_newline ; benchprolog call t_init call t_stop ldis r1, 0 call t_valset call t_start ; /benchprolog ; fib start ldi r1, 9; ldi r10, list@lo ; global pointer ldih r10, list@hi call+ fibcall; ; fib ende ; benchepilog push r0 call+ t_init call+ t_stop call+ t_valget subi r0, r0, 0xc ; offset abziehen pop r3 push r0 push r3 ; /benchepilog call u_init ; weil r10 ueberschrieben wird ldis r1, str@lo ldih r1, str@hi ldis r2, 19 call u_send_string pop r1 call+ u_send_uint call u_send_newline pop r1 call+ u_send_uint call u_send_newline hang: br hang ; 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, -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+