19 lines
221 B
Z80 Assembly
19 lines
221 B
Z80 Assembly
|
|
; 8 bit version
|
||
|
|
; IN : a = n (n <= 13, otherwise overflows)
|
||
|
|
; OUT: a = FIB(n)
|
||
|
|
|
||
|
|
fib8: cp 2
|
||
|
|
ret c ; if n < 2 then done
|
||
|
|
|
||
|
|
ld b,a
|
||
|
|
dec b ; b = n - 1
|
||
|
|
ld c,0 ; F0
|
||
|
|
ld a,1 ; F1
|
||
|
|
|
||
|
|
f8_l: ld d,a
|
||
|
|
add a,c
|
||
|
|
ld c,d
|
||
|
|
djnz f8_l
|
||
|
|
|
||
|
|
ret
|