Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Transfer table addres to function using inline ASM?-solved

Status
Not open for further replies.

Mindaugasu

Member level 3
Joined
Apr 17, 2005
Messages
66
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,288
Activity points
1,753
Re: Transfer table addres to function using inline ASM?-solv

Ok I have concrete question to those who knows AVR-GCC.
My data is in flash memory:

Code:
const uint8_t sinewave[] PROGMEM= //256 values 
{ 
0x80,0x83,0x86,0x89,0x8c,0x8f,.....
I have a function which outputs data from this lookup table to PORTD.

Code:
void signalOUT1(const uint8_t *signal)
{
	uint8_t i=0;
   do{
   PORTD=pgm_read_byte(&signal[i++]);
   }while(1);
}

I looked in compiled listing and I have noticed that pointer address is given to r24 and r25 registers.

Code:
2738 05b6 80E0      		ldi r24,lo8(sinewave)
 2739 05b8 90E0      		ldi r25,hi8(sinewave)
 2740               	.L150:
 2741 05ba 99DD      		rcall signalOUT


And then within function signalOUT r24 and r25 are passed to r31 and r30 by command movw r30,r24.


Is there any way to show a compiler to pass pointer address directly to r30 and r31 (Z) that I could work with inline asm function:

Code:
void signalOUT(const uint8_t *signal, uint8_t ad2, uint8_t ad1, uint8_t ad0)
{
asm volatile("eor r28, r28    ;r28<-0"   "\n\t"
      "eor r29, r29    ;r29<-0"   "\n\t"
      "1:"               "\n\t"
      "add r28, %0   ;1 cycle"         "\n\t"
      "adc r29, %1   ;1 cycle"         "\n\t"   
      "adc %A3, %2   ;1 cycle"         "\n\t"
      "lpm __tmp_reg__, %a3+   ;3 cycles" "\n\t"
      "out %4, __tmp_reg__   ;1 cycle"   "\n\t"
      "rjmp 1b      ;2 cycles. Total 9 cycles"   "\n\t"
      :
      :"r" (ad0),"r" (ad1),"r" (ad2),"e" (signal),"I" (_SFR_IO_ADDR(PORTD))
      :"r28", "r29"
   );
}

because according to avrlibc ) directive "e" (signal) in inline asm assigns a Z pointer to value. Is there some kin of a bug or I am missing something.
Thank you

Added after 5 hours 29 minutes:

Added after 2 minutes:

Just in case someone is interested...

Using static inline function makes compiler optimize code this way, that when calling function table pointer is directly passed to r30:r31 register pair.




---------------------------------------------------
http://www.scienceprog.com
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top