斐波那契数列的前4项为1,1,2,3。已知斐波那契数列满足规则:F(1)=1,F(2)=1, F(n)=F(n-1)+F(n-2)(n ≥ 3,n ∈ N*),请用51单片机汇编语言编程计算出斐波那契数列前16项之和=(第1空)(用10进制表示)
代码如下:
dn0 data 20h; dn1 data 22h
dn2 data 24h
sum data 26h
n data 29h
ORG 0000H
start: MOV R0,#16; MOV n,#1 MOV sum,#0 MOV sum+1,#0 MOV sum+2,#0 again: lcall fibonacci
lcall fsum
inc n
mov dn2,dn1
mov dn2+1,dn1+1 mov dn1,dn0
mov dn1+1,dn0+1 djnz r0,again
stop: sjmp stop
fibonacci: mov a,n
cjne a,#1,next
mov dn0,#1 mov dn0+1,#0 sjmp fret
next: cjne a,#2,next2
mov dn0,#1 mov dn0+1,#0 sjmp fret
next2: mov a,dn1
add a,dn2
mov dn0,a
mov a,dn1+1 addc a,dn2+1 mov dn0+1,a
fret:ret
fsum: mov a,sum
add a,dn0
mov sum,a
mov a,dn0+1 addc a,sum+1 mov sum+1,a
clr a
addc a,#0 mov sum+2,a
ret
end
本文地址:https://blog.csdn.net/qq_45653763/article/details/107906781