Social Icons

twitterfacebookgoogle plusrss feedemail

1/01/2010

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

13.Let F(x)=x3-2x+1. Let x be a 16-bit unsigned number stored in (20-21H), use program to calculate this function and store the result in (30-35H).(2010.01.01.PM06:22)
這應該是1~14題裡面程式碼最長的一題


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


PS:此提程式碼寫得不太好,因為很懶惰直接拿前面題目答案來修改,建議大家利用32*32位原來乘
程式碼如下:
mov source_mul_h,#12h
mov source_mul_l,#34h

;set val
mov a,source_mul_h
mov 50h,a
mov 60h,a
mov a,source_mul_l
mov 51h,a
mov 61h,a

;16*16
mov a,51h
mov b,61h
mul ab
mov source_l,a
mov source_rm,b

mov a,50h
mov b,60h
mul ab
mov source_lm,a
mov source_h,b

mov a,50h
mov b,61h
mul ab
add a,source_rm
mov source_rm,a
mov a,b
addc a, source_lm
mov source_lm,a
mov a,source_h
addc a,#0
mov source_h,a

mov a,51h
mov b,60h
mul ab
add a,source_rm
mov source_rm,a
mov a,b
addc a, source_lm
mov source_lm,a
mov a,source_h
addc a,#0
mov source_h,a

;32*16
source_h equ 20h
source_lm equ 21h
source_rm equ 22h
source_l equ 23h

source_mul_h equ 24h
source_mul_l equ 25h

dest_lh equ 30h
dest_rh equ 31h
dest_lm equ 32h
dest_rm equ 33h
dest_ll equ 34h
dest_rl equ 35h

dest_buf_lh equ 3fh
dest_buf_h equ 40h
dest_buf_lm equ 41h
dest_buf_rm equ 42h
dest_buf_l equ 43h


mov r2,source_mul_l ;time-num
mov r3,source_mul_h ;time-num
mov r4,source_mul_l
mov r5,source_mul_h


;32*16
mul_l_x_source:
mov a,dest_rl
add a,source_l
mov dest_rl,a

mov a,dest_ll
addc a,source_rm
mov dest_ll,a

mov a,dest_rm
addc a,source_lm
mov dest_rm,a

mov a,dest_lm
addc a,source_h
mov dest_lm,a

mov a,dest_rh
addc a,#0
mov dest_rh,a


djnz r2,mul_l_x_source

mul_h_x_source:
mov a,dest_buf_l
add a,source_l
mov dest_buf_l,a

mov a,dest_buf_rm
addc a,source_rm
mov dest_buf_rm,a

mov a,dest_buf_lm
addc a,source_lm
mov dest_buf_lm,a

mov a,dest_buf_h
addc a,source_h
mov dest_buf_h,a

mov a,dest_buf_lh
addc a,#0
mov dest_buf_lh,a

djnz r3,mul_h_x_source

add_dest:
mov a,dest_buf_l
add a,dest_ll
mov dest_ll,a

mov a,dest_buf_rm
addc a,dest_rm
mov dest_rm,a

mov a,dest_buf_lm
addc a,dest_lm
mov dest_lm,a

mov a,dest_buf_h
addc a,dest_rh
mov dest_rh,a


mov a,dest_lh
addc a,dest_buf_lh
mov dest_lh,a


;-2x+1
mov 10h,r5
mov 11h,r4
clr c
mov a,r4
mov b,#2
mul ab
mov r4,a
mov a,dest_rl
subb a,r4
inc a
mov dest_rl,a

mov r4,b
mov a,dest_ll
subb a,r4
mov dest_ll,a

mov a,dest_rm
subb a,#0
mov dest_rm,a

mov a,dest_lm
subb a,#0
mov dest_lm,a

mov a,dest_rh
subb a,#0
mov dest_rh,a

mov a,dest_lh
subb a,#0
mov dest_lh,a


clr c
mov a,r5
mov b,#2
mul ab
mov r5,a

mov a,dest_ll
subb a,r5
mov dest_ll,a

mov r5,b
mov a,dest_rm
subb a,r5
mov dest_rm,a

mov a,dest_lm
subb a,#0
mov dest_lm,a

mov a,dest_rh
subb a,#0
mov dest_rh,a

mov a,dest_lh
subb a,#0
mov dest_lh,a
end

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

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

沒有留言:

張貼留言

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

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