Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-gcc-list] Basic inline asm question [RSS Feed]

#1 Nov. 23, 2005 14:30:14

c.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Basic inline asm question


Hello,

In this scenario:

typedef {
uint16_t x;
uint8_t y;
} T;

T t;

// ...

void function()
{
register uint16_t addr __asm__ ("r30");
register uint8_t addrl __asm__ ("r30");
register uint8_t addrh __asm__ ("r31");

// ...
}

// ...

How to generate in function() this assembly lines (loading address of
global structure in ) using avr-gcc inline asm?
ldi r30, lo8(&t)
ldi r31, hi8(&t)
__asm__ __volatile__("ldi %0, %1" : "=r" (addrl) : "M" (???));
__asm__ __volatile__("ldi %0, %1" : "=r" (addrh) : "M" (???));


I shoud try various typecasts in but the compiler never match
the constraints...


Thanks!


cavanus


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 Nov. 23, 2005 16:32:13

Eric W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Basic inline asm question


cavanus wrote:Hello,

In this scenario:

typedef {
uint16_t x;
uint8_t y;
} T;

T t;

// ...

void function()
{
register uint16_t addr __asm__ ("r30");
register uint8_t addrl __asm__ ("r30");
register uint8_t addrh __asm__ ("r31");

// ...
}

// ...

How to generate in function() this assembly lines (loading address of
global structure in ) using avr-gcc inline asm?
ldi r30, lo8(&t)
ldi r31, hi8(&t)
__asm__ __volatile__("ldi %0, %1" : "=r" (addrl) : "M" (???));
__asm__ __volatile__("ldi %0, %1" : "=r" (addrh) : "M" (???));


I shoud try various typecasts in but the compiler never match
the constraints...Coud you explain more of what you are trying to do by using inlineassembly?--
Eric Weddington


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#3 Nov. 23, 2005 16:48:27

Haase B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Basic inline asm question


Hi,


>How to generate in function() this assembly lines (loading address of
>global structure in ) using avr-gcc inline asm?
>ldi r30, lo8(&t)
>ldi r31, hi8(&t)
>__asm__ __volatile__("ldi %0, %1" : "=r" (addrl) : "M" (???));
>__asm__ __volatile__("ldi %0, %1" : "=r" (addrh) : "M" (???));

For me your example looks like very strange code. My difficulty is that
I do not understand what you plan to do and why you whish to use inline
assembly in the first line. If you whish to force some operand into Z,
it might be better to simply use the "z" register constraint for the
variable you whish to be kept in r30 - r31 and leave it to the compiler
to find the optimum register usage.?
If you could give a bit more details on what you whish to do, we might
be able to help better.

Bjoern.





_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#4 Nov. 23, 2005 16:48:29

Joerg W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Basic inline asm question


cavanus <> wrote:

> void function()
> {
> register uint16_t addr __asm__ ("r30");
> register uint8_t addrl __asm__ ("r30");
> register uint8_t addrh __asm__ ("r31");

That does not make sense at all (IMHO). Variables bound to registers
need to be used on global level. Also, r30/r31 are not available for
that purpose.

> How to generate in function() this assembly lines (loading address
> of global structure in ) using avr-gcc inline asm?

> ldi r30, lo8(&t)
> ldi r31, hi8(&t)
> __asm__ __volatile__("ldi %0, %1" : "=r" (addrl) : "M" (???));
> __asm__ __volatile__("ldi %0, %1" : "=r" (addrh) : "M" (???));

Better explain your overall goal than trying to get the compiler into
generating exact the assembly code you want. If you want to program
in assembly language, don't use a compiler. If you want a compiler,
don't try forcing it to become an assembler.

--
J"org Wunsch Unix support engineer
http://www.interface-systems.de/~j/_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#5 Nov. 30, 2005 19:53:49

c.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Basic inline asm question


Thanks people,

In ethernut source code I find the undocumented asm "i" constraint
that that do this:


extern u_char _irq_stack;
extern u_char _irq_SPL;
extern u_char _irq_SPH;
extern u_char _irq_nesting;

#define _SwitchToIrqStack \
asm volatile ("push r24" "\n\t" // save
r24 to current stack \
"in r24,__SREG__" "\n\t" // load
SREG into r24 \
"push r24" "\n\t" // and
push it to current stack \
"lds r24, _irq_nesting" "\n\t" // load
_irq_nesting in r24 \
"tst r24" "\n\t" // test
for zero \
"brne no_switch1" "\n\t" // jump
to no_switch1 if
not zero \
"in r24, __SP_L__" "\n\t" // load
SP_L into r24 \
"sts _irq_SPL, r24" "\n\t" // and
save it to _irq_SPL \
"in r24, __SP_H__" "\n\t" // load
SP_H into r24 \
"sts _irq_SPH, r24" "\n\t"); // and
save it to _irq_SPH \
asm volatile ("ldi r24, lo8(%0)" "\n\t" // load
lo addr of begin
of irqstack to r24 \
"out __SP_L__, r24" "\n\t" //
write it to SP_L \
"ldi r24, hi8(%0)" "\n\t" // load
hi addr of begin
of irqstack to r24 \
"out __SP_H__, r24" "\n\t" //
write it to SP_H \
"lds r24, _irq_nesting" "\n\t" // load
_irq_nesting to r24 \
"no_switch1:" "\n\t" // jump label \
"inc r24" "\n\t" //
increment r24 \
"sts _irq_nesting, r24" "\n\t" // save
it back to
_irq_nesting \
:: \
"i" (_irq_stack+IRQSTACK_SIZE-1));


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-gcc-list] Basic inline asm question [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support