prog8/examples/fibonacci.p8
2020-08-27 18:10:22 +02:00

26 lines
494 B
Lua

%import c64textio
%zeropage basicsafe
; This example computes the first 20 values of the Fibonacci sequence.
main {
sub start() {
txt.print("fibonacci sequence\n")
repeat 21 {
txt.print_uw(fib_next())
c64.CHROUT('\n')
}
}
uword fib_prev = 0
uword fib_current = 1
sub fib_next() -> uword {
uword new = fib_current + fib_prev
fib_prev = fib_current
fib_current = new
return fib_prev
}
}