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