prog8/examples/fibonacci.p8
Irmen de Jong de06353194 auto select correct library to import based on target, instead of having c64- and cx16- prefix variants
some programs are now 100% source compatible between C64 and Cx16 targets!
import libraries have been rena;med
2020-09-21 00:50:09 +02:00

27 lines
545 B
Lua

%import textio
%zeropage basicsafe
; This example computes the first 20 values of the Fibonacci sequence.
; Note: this program is compatible with C64 and CX16.
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
}
}