avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Using Inline ASM


From: J Wunsch
Subject: Re: [avr-gcc-list] Using Inline ASM
Date: Thu, 8 Mar 2001 11:23:12 +0100 (MET)

Karsten Becker <address@hidden> wrote:

> I want to to perform a swap on a variable so I use the command asm("swap
> stat"); where stat is my u08 variable.

Someone recently (re-)posted an introduction to asm statements in gcc
here, you should find this in the archive of the list.

asm volatile("swap %0", "=r" (stat) : "0" (stat));

should do the trick.  In short, it means that gcc must not move the
asm instruction away from that place in the code during optimization
(`volatile'), and that the compiler should assign exactly one register
("r") for the assembler statement which also gets the result by the
asm statement ("="), and that it should either keep the variable
`stat' in that register or it should arrange for code to copy the
contents in and out of that variable.  The "0" means that the asm
instruction uses the same operand for input and output.

Too bad the optimizer doesn't completely detect the case in:

    stat = (stat << 4) | (stat >> 4);

although it's not too bad at all:

        mov r25,r24
        swap r24
        andi r24,0xf0
        swap r25
        andi r25,0x0f
        or r25,r24

-- 
J"org Wunsch                                           Unix support engineer
address@hidden         http://www.interface-systems.de/~j



reply via email to

[Prev in Thread] Current Thread [Next in Thread]