Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/26/08 21:09
Modified:
  11/26/08 21:13

Read: times


 
#160329 - It depends ... read the datasheet ... then guess
Responding to: ???'s previous message
Apperently, you're a 'C' programmer. The construct to which you seem, sort-of, to allude, exists as indirect addressing. That's accomplished by using R0, R1, or DPTR.

There are instructions intended specifically for use with the DPTR, and there's an addressing mode for them. The DPTR is intended as an indirect memory address register. 805x allows you to load and increment it directly, and, in some variants, to decrement it, too. A very few even allow you to increment it or decrement it automatically with each use.

The instruction, MOVC A,@A+DPTR tells the execution unit to load A with the data found in code space at the effective address formed by the sum of DPTR and the content of A. The instruction MOVX @DPTR,A tells the execution unit to take the content of A and store it at the location in "external" data space to which DPTR points. Internal memory, of which there are typically only 256 bytes, can be accessed by the same mechanism, albeit using registers R0 and R1 rather than the data pointer (DPTR).


Assigning DPTR the value #TEXT loads DPTR with the address of TEXT. DPTR is a BYTE pointer, though, since the 805x is a BYTE processor.

Now, suppose you have a region in code space labeled TEXT: and a string of "Hello World" located there, followed by 0x0D, and that followed by a 0x00, then you might use code like this.

;
OUTSTRING:
	POP	DPH			; 
	POP	DPL			; 
	ACALL	OUTCHAR			; Call the output loop
	JMP	@A+DPTR			; Jump to the address after the string
OUTCHAR:	
        CLR A			        ; 
	MOVC	A,@A+DPTR		; Get the next character
	INC	DPTR			; bump the pointer
	JZ	ENDSTR			; zero defines end of string
	LCALL	TXCHR	                ; else ship it, using TXCHR then  
                                        ;  -- TXCHR is the character transmitter routine
	SJMP	OUTCHAR			; do it again until told otherwise
;
ENDSTR:	RET				; Return to caller
;


I can't take credit for this ... it was gleaned from within someone else's work ... but works well.

As for your question, "What happens when you load the DPTR register with ascii-code for text?" Well, that depends entirely on the text and what's in code space at the location defined by those two characters. If your assembler allows you to load a multi-byte value into a two-byte register, which it shouldn't, then the DPTR will point to whatever location in either code or data space you define with those two bytes. What happens after that is dependent entirely on what, if anything, you do with that data pointer before you change it to something meaningful.

RE

List of 9 messages in thread
TopicAuthorDate
Loading DPTR with ascii code            01/01/70 00:00      
   Used to?            01/01/70 00:00      
      Indirect addressing mode on text            01/01/70 00:00      
         How an assembler works            01/01/70 00:00      
      that is context sensitive!            01/01/70 00:00      
   It depends ... read the datasheet ... then guess            01/01/70 00:00      
   Right back to basics - really foundational stuff            01/01/70 00:00      
   The one thing it most certainly does not do...            01/01/70 00:00      
      Thanks!!            01/01/70 00:00      

Back to Subject List