This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to retrieve data from a DPTR(16 bits) when registers are only 8bits

Hi All,

I'm facing a problem with assembly coding here..

CSEG AT 0100H
LABEL:   DB  "TESTING TESTING 1 2 3]"

TRANS:
	MOV	DPTR,#LABEL	;load data pointer with LABEL's address
	MOV 	R0,DPL
	LJMP	SEND_TO_TXD
	CLR	TI
	RET

SEND_TO_TXD:
	CLR	TI
	MOV 	SBUF,@R0   			INC 	R0
	JNB	TI,$
	CJNE	@R0,#']',SEND_TO_TXD
	RET

I want to send the string of characters in LABEL to SBUF. But the above code cannot work because by loading DPL to R0, i'm only loading address 00H to R0 hence data transferred to SBUF will be data at address 00H instead of LABEL.

Assuming that addresses from 00H - FFH have all been used up and i can only define byte starting from 0100H, does anyone has any idea on how to move the data which DPTR is pointing to, to SBUF which can only takle in 8 bits at a time.

Parents
  • "Am i right to say that by using the above instruction, i am actually adding 00H (for the first loop) to the address pointed to by DPTR, and then shift the contents to the accumulator?"

    Yes, DPTR remains constant while R0 (thus ACC) increments as an offset from the constant address contained in DPTR. Without varying DPTR, the routine can only support strings as long as 256 bytes (which is probably reasonable). Instead, by always using a zero offset and incrementing DPTR, one can avoid the 256-byte limitation:

    CSEG AT 0100H
    LABEL:   DB  "TESTING TESTING 1 2 3]"
    
    TRANS:
    	MOV	DPTR,#LABEL	;load data pointer with LABEL's address
    	LJMP	SEND_TO_TXD
    	CLR	TI
    	RET
    
    SEND_TO_TXD:
    	CLR	TI
            CLR     A
            MOVC    A,@A+DPTR
    	MOV 	SBUF,A
            INC 	DPTR
    	JNB	TI,$
    	CJNE	A,#']',SEND_TO_TXD
    	RET

Reply
  • "Am i right to say that by using the above instruction, i am actually adding 00H (for the first loop) to the address pointed to by DPTR, and then shift the contents to the accumulator?"

    Yes, DPTR remains constant while R0 (thus ACC) increments as an offset from the constant address contained in DPTR. Without varying DPTR, the routine can only support strings as long as 256 bytes (which is probably reasonable). Instead, by always using a zero offset and incrementing DPTR, one can avoid the 256-byte limitation:

    CSEG AT 0100H
    LABEL:   DB  "TESTING TESTING 1 2 3]"
    
    TRANS:
    	MOV	DPTR,#LABEL	;load data pointer with LABEL's address
    	LJMP	SEND_TO_TXD
    	CLR	TI
    	RET
    
    SEND_TO_TXD:
    	CLR	TI
            CLR     A
            MOVC    A,@A+DPTR
    	MOV 	SBUF,A
            INC 	DPTR
    	JNB	TI,$
    	CJNE	A,#']',SEND_TO_TXD
    	RET

Children