Social Icons

twitterfacebookgoogle plusrss feedemail

12/31/2009

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

10.Write a program to change a 16-bit unsigned number stored in 20H-21H into a 2-byte BCD at 30H-31H. For example, if (20H)=0FH, (21H)=13H, then (30H)=38FH, (31H)=59H. Assume the number stored in (20H-21H) is less than 10000 in decimal.(2009.12.31.PM.09:48將程式碼附上)(2010.01.03.PM11:32更新幾個錯字)
 本文章題目版權歸屬於朱老師,另外本文所提供答案並不保證其正確性


程式碼如下:
source_h equ 20H
source_l equ 21H
dest_h equ 30H
dest_l equ 31H

mov r3,#2h
mov source_h,#0fH
mov source_l,#13H

clr c
mov r0,source_h
mov r1,source_l
subb_low:
mov a,r1
subb a,#64H
mov r1,a
jnc time_num

borrow:
mov a,r0
subb a,#0H
mov r0,a
jc over

time_num:
inc r2
jmp subb_low

over:
mov a,r1
add a,#64H
mov r1,a

mov dest_h,r2
mov dest_l,r1

unsign_to_BCD:
mov a,dest_h
mov b,#10
div ab
mov dest_h,b
mov b,#10H
mul ab
add a,dest_h
mov dest_h,a

mov a,dest_l
mov b,#10
div ab
mov dest_l,b
mov b,#10H
mul ab
add a,dest_l
mov dest_l,a


end

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



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

沒有留言:

張貼留言

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

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