Write a PIC18 Assembly Language Program to transfer a string
Write a PIC18 Assembly Language Program to transfer a string of data from code space starting at address space 200H to RAM locations inside the CPU starting 40H. The data representing your last name and first name is as shown below: MYDATA: DB, \"Alex Young\", 0 (RW Freeman).
After Data has been transferred from ROM space into RAM, the subroutine should copy the data from RAM locations starting at 40H to RAM locations starting at 60H.
Solution
PART I:
Using counter method:
ORG 0000
MOV DPTR, #MYDATA ;load ROM pointer
MOV P0, #40H ;load RAM pointer
MOV P2, #7 ;load counter
BACK; CLR A ;A = 0
MOVC A,@A+DPTR ;move data from code space
MOV @PO,A ;save it in RAM
INC DPTR ;increment ROM pointer
INC P0 ;increment RAM pointer
DJNZ P2,BACK ;loop until counter=0
HERE; SJMP HERE
;------------------On-Chip code space used for storing data
ORG 200H
MYDATA DB \"Alex Young\"
END
PART II:
MOV P0, #40H ; P0 is a pointer which is starting from 40H
MOV P1, #60H ; P1 is the other pointer which is starting from 60H
MOV P3, #10 ; 10 iterations
Back: MOV A, @P0 ; loop
MOV @P1, A
INC P0
INC P1
DJNZ P3, Back
