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
  • CSEG AT 0100H
    LABEL:   DB  "TESTING TESTING 1 2 3]"
    
    TRANS:
    	MOV	DPTR,#LABEL	;load data pointer with LABEL's address
    	MOV 	R0,#0
    	LJMP	SEND_TO_TXD
    	CLR	TI
    	RET
    
    SEND_TO_TXD:
    	CLR	TI
            MOV     A,R0
            MOVC    A,@A+DPTR
    	MOV 	SBUF,A
            INC 	R0
    	JNB	TI,$
    	CJNE	A,#']',SEND_TO_TXD
    	RET

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

Children
  • Hey Dan!

    Thanks for the great help!

    I've refered the instruction ( MOVC A,@A+DPTR )in the book by THOMAS W SCHULTZ and the book explains the above instruction is to move contents pointed by sum of DPTR and ACC into ACC.

    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?

  • Just a quick question.

    Previously i've done the following.

    
    CSEG AT 00F0H
    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
    

    Instead of displaying the string of characters in LABEL, my hyperterminal displayed trash. What could be the problem?

    Can characters defined under code segment simply be displayed like this? Is certain part of the memory only meant for code, and certain part only meant for data?

  • "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

  • "Can characters defined under code segment simply be displayed like this?"

    No, the only (conventional) way to access code memory is using MOVC.

    "Is certain part of the memory only meant for code, and certain part only meant for data?"

    Yes, @RO (and @R1) only access internal data memory. MOVX is used to access memory classified as "external" data memory.

  • Hey Dan!!

    I'm really thankful for your help and the information you have provided. What you have said is very useful to me.

    I can't wait to return to my lab tomorrow to do some testings...

    Once again, appreciate your help! =)

    Have a great day!

  • "I'm really thankful for your help and the information you have provided. What you have said is very useful to me."

    You're welcome. If you haven't read it already, the following document describes the various 8051 memory spaces and the instructions used to access them.

    http://www.semiconductors.philips.com/acrobat_download/various/80C51_FAM_ARCH_1.pdf