2019-01-27 00:02:45 +00:00
|
|
|
%import c64utils
|
2019-02-02 23:14:56 +00:00
|
|
|
%zeropage basicsafe
|
2019-01-27 00:02:45 +00:00
|
|
|
|
|
|
|
; This example computes the first 20 values of the Fibonacci sequence.
|
|
|
|
|
2019-07-29 21:11:13 +00:00
|
|
|
main {
|
2019-01-27 00:02:45 +00:00
|
|
|
sub start() {
|
|
|
|
c64scr.print("fibonacci sequence\n")
|
2020-07-24 20:57:19 +00:00
|
|
|
|
|
|
|
; TODO fix the double i=0 assignment generation in the asm code:
|
|
|
|
|
|
|
|
ubyte i
|
|
|
|
for i in 0 to 20 {
|
2019-01-27 00:02:45 +00:00
|
|
|
c64scr.print_uw(fib_next())
|
|
|
|
c64.CHROUT('\n')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2020-03-22 21:47:05 +00:00
|
|
|
uword new = fib_current + fib_prev
|
|
|
|
fib_prev = fib_current
|
|
|
|
fib_current = new
|
|
|
|
return fib_prev
|
2020-03-12 23:27:33 +00:00
|
|
|
}
|
2019-01-27 00:02:45 +00:00
|
|
|
}
|