next up previous contents
Next: Matrix Multiplication Up: The Fibonacci calculator Previous: The MatLab implementation   Contents

The TONS implementation

This code was run on the 0.0.6 release of the TONS program available via anonymous FTP from ftp://ftp.sslug.dk/pub/TONS/.

;;
;; Fibonacci caluclator
;;
;; f(n) =    f(n-1)+f(n-2)    if n > 2
;;      =    n                otherwise
;;
entry "fib"
        decl integer,   ; r0
             integer,   ; r1
             integer,   ; r2
             integer    ; r3
        cmpgt r0, a0, 2
        branch r0
         move r1, a0
         decr r1
         call r2, "fib", r1
         decr r1
         call r3, "fib", r1
         add r2, r3
         return r2
        else
         return a0
        end
end




1999-08-09