mirror of
https://github.com/irmen/prog8.git
synced 2024-12-29 04:29:19 +00:00
29 lines
611 B
Lua
29 lines
611 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.
|
|
|
|
; TODO why is this larger than on the previous compiler version?
|
|
|
|
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
|
|
}
|
|
}
|