Saturday, April 30, 2016

8051 Program – exchange content of two ram locations

; exchange content of two ram locations
ORG 0H
MEM1_ADDR EQU 40H
MEM2_ADDR EQU 60H
BYTE_COUNT EQU 10
MAIN :
MOV R0,#MEM1_ADDR
MOV R7,#BYTE_COUNT
MOV A, #0
mem1fill:MOV @R0,A
INC A
INC R0
DJNZ R7,mem1fill
MOV R0,#MEM2_ADDR
MOV R7,#BYTE_COUNT
MOV A, #10H
mem2fill:MOV @R0,A
INC A
INC R0
DJNZ R7,mem2fill
MOV R0,#MEM1_ADDR
MOV R1,#MEM2_ADDR
MOV R7,#BYTE_COUNT
LCALL XCHANGE
SJMP MAIN
XCHANGE:
MOV A, #0
loop: MOV A, @R0
MOV B, @R1
MOV @R1, A
MOV @R0, B
INC R0
INC R1
DJNZ R7, loop
RET
END

; exchange block of data
; using XCH instruction
ORG 0H
SJMP 30H
ORG 30H
MOV R0,#27H ;source address
MOV R1,#41H ;destination address
MOV R3,#05H ;count
BACK:
MOVX A,@r0
MOV r2,a
MOVX a,@r1
XCH a, r2
MOVX @r1,a
XCH a, r2
MOVX @r0,a
INC R0
INC R1
DJNZ R3, BACK
HERE: SJMP HERE
END



Related topics:
8051 Program - move block of data without overlap   |   8051 Program - move block of data with overlap   |   8051 Program - move block of data external memory   |   8051 Program - exchange block of data external memory   |   8051 Program - memory compare   |   8051 Program - swap nibbles   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment