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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/11/06 05:44
Read: times


 
#120005 - correct
Responding to: ???'s previous message
hi,

Mike Collins said:
Would it be correct to manually get the address of a label defined in a lookup table to calculate the start in DPTR and then add whatever offset you need (in ACC) by adding ACC to DPL? i.e.

table:
dw elm0,elm1,elm2,elm3

elm0:
blah
blah

elm1:
blah
blah

elm2:
blah
blah

Yes, this way is correct. Just note about DW statement: depend on compiler it may use Big or Little Endian format to place 16-bit value into program memory. So you should take care about how to restore that address back into DPTR.
For example, Keil places high byte of address firstly so I use next subroutine:
; here we have number of table (elmN) we look for in Accumulator (0...127)
; and DPTR is loaded with address of table of 16-bit pointers to them
DPTR_FROM_CDPTR_AX2:
; calculate dimension over table of 16-bit values
	ADD	A,ACC				; x2 due 16 bit 
	ADD	A,DPL
	MOV	DPL,A
	JNC	ADD_DPTR_END
	INC	DPH
ADD_DPTR_END:
;here DPTR contains pointer to the 16-bit address of table (elmN)
; load this address into DPTR
	MOV	A,#1
	MOVC	A,@A+DPTR			; low byte of address
	PUSH	ACC
	CLR	A
	MOVC	A,@A+DPTR			; high byte of address
	MOV	DPH,A
	POP	DPL
	RET
Regards,
Oleg

List of 9 messages in thread
TopicAuthorDate
Lookup table, manual            01/01/70 00:00      
   if you want a maintenance nightmare            01/01/70 00:00      
   Lookup table            01/01/70 00:00      
   Lookup table.            01/01/70 00:00      
   correct            01/01/70 00:00      
      big endian            01/01/70 00:00      
         little endian (just to add some confusion:)            01/01/70 00:00      
            little endian -8051            01/01/70 00:00      
      Thanks Oleg            01/01/70 00:00      

Back to Subject List