改进代码 ORG 0000H LJMP MAIN ORG 4040H MAIN:MOV R0,#30H; MOV R2,#16; CLR A; A1:MOV @R0,A; INC R0; INC A; DJNZ R2,A1; MOV R0,#30H; MOV R1,#40H; MOV R2,#10H; A2:MOV A,@R0; MOV @R1,A; INC R0; INC R1; DJNZ R2,A2; MOV R1, #40H; MOV DPTR,#4800H; MOV R2, #10; A3:MOV A, @R1; MOVX @DPTR,A; INC R1; INC DPTR; DJNZ R2,A3; MOV SP,#60H; MOV R2,#10H; MOV DPTR,#4800H; PUSH DPL; PUSH DPH; MOV DPTR,#5800H; MOV R3,DPL; MOV R4,DPH; A4:POP DPH; POP DPL; MOVX A,@DPTR; INC DPTR; PUSH DPL; PUSH DPH; MOV DPL,R3; MOV DPH,R4; MOVX @DPTR,A; INC DPTR; MOV R3,DPL; MOV R4,DPH; DJNZ R2,A4; MOV R0,#50H; MOV DPTR,#5800H; MOV R2,#10H; A5:MOVX A,@DPTR; MOV @R0,A; INC R0; INC DPTR; DJNZ R2,A5; HERE:SJMP HERE; END
时间: 2023-07-15 11:11:10 浏览: 154
以下是改进后的代码:
ORG 0000H
LJMP MAIN
ORG 4040H
MAIN:
; initialize variables
MOV R0, #30H
MOV R1, #40H
MOV R2, #16
MOV R3, #10H
MOV R4, #50H
; fill array with values
A1:
MOV @R0, A
INC R0
INC A
DJNZ R2, A1
; copy array to memory block
A2:
MOV A, @R0
MOV @R1, A
INC R0
INC R1
DJNZ R3, A2
; copy memory block to external memory
A3:
MOV A, @R1
MOVX @DPTR, A
INC R1
INC DPTR
DJNZ R3, A3
; set stack pointer and copy data from memory block to stack
MOV SP, #60H
MOV R2, #10H
MOV DPTR, #4800H
PUSH DPL
PUSH DPH
MOV DPTR, #5800H
A4:
POP DPH
POP DPL
MOVX A, @DPTR
INC DPTR
PUSH DPL
PUSH DPH
MOV DPL, R3
MOV DPH, R4
MOVX @DPTR, A
INC DPTR
MOV R3, DPL
MOV R4, DPH
DJNZ R2, A4
; copy data from memory block to array
MOV DPTR, #5800H
MOV R2, #10H
A5:
MOVX A, @DPTR
MOV @R4, A
INC R4
INC DPTR
DJNZ R2, A5
HERE:
SJMP HERE
END
阅读全文