[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] inline ASM newbie problem
From: |
Joerg Wunsch |
Subject: |
Re: [avr-gcc-list] inline ASM newbie problem |
Date: |
Tue, 11 Oct 2005 19:40:12 +0200 (MET DST) |
"Marco Randazzo" <address@hidden> wrote:
> I would like to pass a simple input value to an asm routine but compiler =
> says "error: impossible constraint in `asm'" and I can't understand what =
> I've to do. Here is my code:
> uint8_t servo_prot_offset;
> [...]
> asm volatile (
> "\n"
> "PUSH R18" "\n\t"
> "PUSH R24" "\n\t"
> "PUSH R25" "\n\t"
> " LDI R24,0x00" "\n\t"
> " LDI R25,0x00" "\n\t"
> "l1 : ADIW R24,0x01" "\n\t"
> " LDI R18,0x06" "\n\t"=20
> " CPI R24,%0 " "\n\t" <--- HERE I WANT COMPARE R24 WITH =
> THE VALUE OF servo_prot_offset
> " CPC R25,R18 " "\n\t"
> " BRCS l1" "\n\t"
> "POP R25" "\n\t"
> "POP R24" "\n\t"
> "POP R18" "\n\t"
> : //output operands
> : "M" (servo_prot_offset) //input operands
> );
See the inline assembler documentation (part of avr-libc docs).
Constraint "M" would expect an 8-bit integer constant, but you're
trying to pass an 8-bit variable, yet your CPI instruction would
expect a constant literal again. Something doesn't fit right
together.
Perhaps you try first expressing your desire in C. Did you verify the
generated code from C?
Also, don't push/pop your own stuff. Instead, use the "clobbers"
section of the inline asm statement to tell the compiler which
registers you are destroying, or even better, invent a couple of
scratch variables in the surrounding C code, and pass them down to
your inline asm statement (e.g. using "d" constraints). Also, you are
always allowed to use __tmp_reg__ as a scratch register. That way,
you'll give the compiler freedom to arrange the register usage
appropriately, so most likely, no additional push/pop operations will
be required at all.
--
cheers, J"org .-.-. --... ...-- -.. . DL8DTL
http://www.sax.de/~joerg/ NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)