Social Icons

twitterfacebookgoogle plusrss feedemail

1/02/2010

微處理機(8051)第一次上機題目第二題 memory-move

2.Write a program to process data stored in the external code memory from 1000H to 104FH. The rule of the processing is as follows :
甲、 If the data is even, copy it to external data memory started from 2000H.
乙、 If the data is odd, copy it to on-chip memory started from 40H.
丙、 Find out how many odd numbers and how many even numbers during the processing. Stored the number of odd numbers in A and the number of even numbers in B.

這題是老師第一次上機測驗時,發給我們的題目第二題。

老師在上次上課中有把答案寫出來放在BB
不過我用Keil uVision3 跑過一次之後發現出了點問題
下面程式碼是經過我修改之後
內容跟原本差異不大
主要也是指令用錯的問題
大家可以看看



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

程式碼如下:
ORG 1000H
DB 1,2,3,4,5

ORG   00H
ODD_NUM EQU R6
EVEN_NUM EQU R7

ROM_ADDR_DPH EQU 30H
ROM_ADDR_DPL EQU 31H
XDATA_ADDR_DPH EQU 32H
XDATA_ADDR_DPL EQU 33H
SRAM_ADDR EQU R0

MOV ROM_ADDR_DPH, #10H
MOV ROM_ADDR_DPL, #00H
MOV XDATA_ADDR_DPH, #20H
MOV XDATA_ADDR_DPL, #00H
MOV SRAM_ADDR, #40H 

MOV ODD_NUM,#0
MOV EVEN_NUM,#0 
MOV R1,#50H
AGAIN : 
MOV DPH, ROM_ADDR_DPH
MOV DPL, ROM_ADDR_DPL
CLR  A
MOVC A,@A+DPTR
INC DPTR
MOV ROM_ADDR_DPH, DPH
MOV ROM_ADDR_DPL, DPL
MOV R4,A
MOV B,#2
DIV AB
mov A,B
JZ EVEN

ODD:  
MOV A,R4
MOV @R0,A
INC SRAM_ADDR
INC ODD_NUM
JMP NEXT
EVEN:
MOV DPH, XDATA_ADDR_DPH
MOV DPL, XDATA_ADDR_DPL
MOV A,R4
MOVX @DPTR,A
INC DPTR
MOV XDATA_ADDR_DPH, DPH
MOV XDATA_ADDR_DPL, DPL
INC EVEN_NUM
NEXT:
DJNZ R1,AGAIN
MOV A,ODD_NUM
MOV B,EVEN_NUM

end

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


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

沒有留言:

張貼留言

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

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