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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/17/04 03:38
Read: times


 
#64916 - RE: data table
Responding to: ???'s previous message
Looks to me like Ron has more than 256 elements in his table. As such the indexing to a particular element will require some additional manipulation. I looked at the table and noticed that he has some 424 elements so to design a more generic mechanism that has support of up to 64K elements will require doing arithmentic on the DPTR value.

Lets first look at how this looks as a C example (for simplicity I do not show the initialized table):

unsigned char code array[1024];

unsigned char get_item(unsigned int item_no)
{
	return(array[item_no]);
}


Now if we made an assembler language equivalent of this lets look at how it would be coded. Similar to the above lets play around with a 1K byte table in the code space.

ARRAY:
    DB  000H,000H,000H,000H,000H,000H,000H,000H
    DB  000H,000H,000H,000H,000H,000H,000H,000H
    ;
    ; .... up to 1024 initialized bytes...
    ;      just zeros shown here
    ;
    DB  000H,000H,000H,000H,000H,000H,000H,000H
;
; Subroutine to fetch element from table > 256 bytes.
; Entry:  R1::R0 is the index into the table
; Exit:   A is the fetched table value
; Uses:   DPTR is modified by this routine
;
GET_ITEM:
   MOV    A,#LOW(ARRAY)    ;get low byte of array  offset
   ADD    A,R0
   MOV    DPL,A
   MOV    A,#HIGH(ARRAY)   ;get high byte of array ofset
   ADDC   A,R1
   MOV    DPH,A
   CLR    A                 
   MOVC   A,@A+DPTR        ;get content at array offset
   RET  	


Good Luck,
Michael Karas



List of 3 messages in thread
TopicAuthorDate
data table            01/01/70 00:00      
   RE: data table            01/01/70 00:00      
   RE: data table            01/01/70 00:00      

Back to Subject List