prog8/examples/fibonacci.p8

27 lines
549 B
Plaintext
Raw Normal View History

%import textio
%zeropage basicsafe
2019-01-27 00:02:45 +00:00
; This example computes the first 20 values of the Fibonacci sequence.
; Note: this program can be compiled for multiple target systems.
2019-01-27 00:02:45 +00:00
2019-07-29 21:11:13 +00:00
main {
2019-01-27 00:02:45 +00:00
sub start() {
2020-08-27 16:10:22 +00:00
txt.print("fibonacci sequence\n")
2020-07-25 20:54:50 +00:00
repeat 21 {
2020-08-27 16:10:22 +00:00
txt.print_uw(fib_next())
2022-03-27 15:46:15 +00:00
txt.nl()
2019-01-27 00:02:45 +00:00
}
}
2020-03-22 22:50:15 +00:00
uword fib_prev = 0
uword fib_current = 1
2019-01-27 00:02:45 +00:00
sub fib_next() -> uword {
uword new = fib_current + fib_prev
fib_prev = fib_current
fib_current = new
return fib_prev
}
2019-01-27 00:02:45 +00:00
}