Social Icons

twitterfacebookgoogle plusrss feedemail

1/01/2010

微處理機(8051)上機考古題 Arithmetic 2-14

14.Define a sequence that f(n+2)=f(n+1)+f(n). Let f(0)=0 and f(1)=1 and n is a BCD number stored in 20H.
Please use program to calculate n from 0 to 30 and stored the result in BCD form at .(30-32H)
.(2010.01.01.PM09:44經做准呈提醒,更新小錯誤)
 呼~新年的第一天寫出這題
注意:
此題  n的範圍應做修改
請改成 0 to 28
否則30H~32H放不下


 本文章題目版權歸屬於朱老師,另外本文所提供答案並不保證其正確性


程式碼如下:
n equ 20h
dest_h equ 30H
dest_m equ 31H
dest_l equ 32H
dest_buf_1h equ 33H
dest_buf_1m equ 34H
dest_buf_1l equ 35H
dest_buf_2h equ 36H
dest_buf_2m equ 37H
dest_buf_2l equ 38H

mov dest_buf_1h,#00H
mov dest_buf_1m,#00H
mov dest_buf_1l,#01H
mov dest_buf_2h,#00H
mov dest_buf_2m,#00H
mov dest_buf_2l,#01H

mov n,#5
;n=0
mov a,n
jz f_2

;n>=1
mov a,n
again:
;n=odd
dec a
mov r0,a

mov a,dest_buf_1l
add a,dest_buf_2l
da a
mov dest_l,a
mov dest_buf_1l,a

mov a,dest_buf_1m
addc a,dest_buf_2m
da a
mov dest_m,a
mov dest_buf_1m,a

mov a,dest_buf_1h
addc a,dest_buf_2h
da a
mov dest_h,a
mov dest_buf_1h,a

mov a,r0
jz over

;n=even
dec a
mov r0,a

mov a,dest_buf_2l
add a,dest_buf_1l
da a
mov dest_l,a
mov dest_buf_2l,a

mov a,dest_buf_2m
addc a,dest_buf_1m
da a
mov dest_m,a
mov dest_buf_2m,a

mov a,dest_buf_2h
addc a,dest_buf_1h
da a
mov dest_h,a
mov dest_buf_2h,a

mov a,r0
jz over
jmp again

f_2:
mov dest_l,dest_buf_1l

over:
nop

end

如果要複製上方程式碼,請點擊程式碼上方的    圖示會跳出一個視窗,複製即可

如果發現文章有錯誤,歡迎留言告知~謝謝指教!

沒有留言:

張貼留言

俗話說
凡走過必留下痕跡,凡住過必留下鄰居
凡爬過必留下樓梯,凡來過必留下IP
看過文章之後歡迎留下您寶貴的意見喔!

 
 
无觅相关文章插件,迅速提升网站流量