Conveying const pointer from 8051 C to ASM

Hi

Following code snippet:

------------C PROGRAM---------------------------

const unsigned int code TABLE1[4] = {1,2,3,4}; //constants stored in flash const unsigned int code TABLE2[4] = {5,6,7,8}; const unsigned int code TABLE3[4] = {44,33,44,33};

unsigned int *TableStart;

void main (void) {

TableStart = &TABLE1[0]; //get address of TABLE1[0] int_isr(); TableStart = &TABLE2[0]; int_isr(); TableStart = &TABLE3[0]; int_isr();

}

------------ASM PROGRAM---------------------------

EXTRN DATA (TableStart)

int_isr: mov A, #0 ;I want first byte in TABLEx mov DPTR, #TableStart ;get address of TABLEx mov A, @A+DPTR ;put first table value into ACC reti

END

--------------------------------------------------

My aim is to dynamically send a TableStart address from a C program into an ASM interrupt handler (in my example above the ISR is called direct for the purposes of my question - I would normally connect int_isr to a real interrupt, with the C program "stuck" in a while(1) loop).

The result of the code above is that, in int_isr, the DPTR will end up with the address (in RAM) of the TableStart pointer. Instead, I want it to contain the contents of TableStart (which is the start address of the table). How can I achieve this?

Thank you Jack

Reply to
Jack
Loading thread data ...

"Jack" schreef in bericht news: snipped-for-privacy@posting.google.com...

Should that be something like MOVC A,@A+DPTR ;put first table value into ACC

MOVC, to fetch something from code memory.

--
Thanks, Frank.
(remove 'x' and 'invalid' when replying by email)
Reply to
Frank Bemelman

In addition you must save and restore your DPTR contents in the isr.

Reply to
CBarn24050

Thank you - refer to my response in article with subject = "Using "mov DPTR, #data16" in 8051 ASM"

Reply to
Jack

Anything wrong with:

mov DPTR, TableStart ; note the removal of the #

??

Rufus

(I haven't coded the 8051 in a while, so bear with me)

Reply to
Rufus V. Smith

  1. There is only one instruction loading the whole DPTR. It loads the 16 bit (immediate) constant from the instruction. The 8051 assembler marks immediate constants with a '#'.
  2. If there were an instruction like you showed, it should load the 16 bit data from the first two bytes of TableStart.
  3. To load a variable into DPTR, use:

mov DPH, high_ptr mov DPL, low_ptr

HTH

Tauno Voipio tauno voipio (at) iki fi

Reply to
Tauno Voipio

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.