[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] inline assembler problem
From: |
Christoph Plattner |
Subject: |
Re: [avr-gcc-list] inline assembler problem |
Date: |
Fri, 17 Aug 2001 08:22:39 +0200 |
Hello !
I HAVE GOT IT !
The varible "bit" is an input not an output parameter !!
So it is in the wrong line of the __asm__ __volatile__ statement !
I think you have to write:
__asm__ __volatile__ (
"code...." "\n\t"
.
.
"code...." "\n\t"
: "=r" (crchi), "=r" (crclo)
: "0" (crchi), "1" (crclo), "=r" (bit)
: "r24", .... << registers that may be modified and
the compiler has to concern about !
);
Further: what is "=&r" ? I only know "=r", and if I want to reference
a memory (pointer), then "=m" is used.
With friendly regards
Christoph P.
------------------------------------------------------------------
private: address@hidden
company: address@hidden
Michael Jochum wrote:
>
> hi all!
>
> i am writing a crc function and cant get the inline asm code to work.
> the pure c-code is working.
> as you can see in crc.s the cpc instruction gets the wrong parameter.
> what is the problem with this code?
>
> i use:
> gcc version 3.0.1 20010806 (prerelease)
> binutils version version 2.11.90 20010814
> avr-libc-20010717
>
> and cmd is:
> avr-gcc -O3 -mmcu=at90s4433 -c crc.c -S -o crc.s
>
> tia,
> michael.
>
> --- crc.asm ---
> #include <io.h>
>
> static unsigned char crchi;
> static unsigned char crclo;
>
> void crcbit(unsigned char bit){
> #if 1
> asm volatile(
> "clc" "\n\t"
> "ror %0" "\n\t"
> "ror %1" "\n\t"
> "cpc %2,__zero_reg__" "\n\t"
> "breq crc_skip_op" "\n\t"
> "push r24" "\n\t"
> "ldi r24,0x84" "\n\t"
> "eor %0,r24" "\n\t"
> "ldi r24,0x08" "\n\t"
> "eor %1,r24" "\n\t"
> "pop r24" "\n\t"
> "crc_skip_op:" "\n\t"
> : "=r" (crchi), "=r" (crclo), "=&r" (bit)
> : "0" (crchi), "1" (crclo)
> : "0", "1"
> );
> #else
> unsigned char tmp = crclo & 1; //rotate the 16 bits to the right
> crclo = crclo >> 1;
> crclo |= (crchi & 1) << 7;
> crchi = crchi >> 1;
>
> if (((tmp & 0x01)^bit) ==0x01){
> crchi = crchi^0x84;
> crclo = crclo^0x08;
> }
> #endif
> }
>
> main() {
> crclo=crchi=0xff;
> for(;;) {
> crcbit(1);
> crcbit(0);
> }
> }
>
> --- crc.s ---
> .file "crc.c"
> .arch at90s4433
> __SREG__ = 0x3f
> __SP_H__ = 0x3e
> __SP_L__ = 0x3d
> __tmp_reg__ = 0
> __zero_reg__ = 1
> _PC_ = 2
> .text
> .global crcbit
> .type crcbit,@function
> crcbit:
> /* prologue: frame size=0 */
> /* prologue end (size=0) */
> lds r19,crchi
> lds r18,crclo
> mov r20,r19
> mov r22,r18
> /* #APP */
> clc
> ror r20
> ror r22
> cpc r18,__zero_reg__ <<<< problem
> breq crc_skip_op
> push r24
> ldi r24,0x84
> eor r20,r24
> ldi r24,0x08
> eor r22,r24
> pop r24
> crc_skip_op:
>
> /* #NOAPP */
> mov r21,r20
> mov r18,r22
> sts crchi,r21
> sts crclo,r18
> /* epilogue: frame size=0 */
> ret
> /* epilogue end (size=1) */
> /* function crcbit size 39 (38) */
> .Lfe1:
> .size crcbit,.Lfe1-crcbit
> .global main
> .type main,@function
> main:
> /* prologue: frame size=0 */
> ldi r28,lo8(__stack - 0)
> ldi r29,hi8(__stack - 0)
> out __SP_H__,r29
> out __SP_L__,r28
> /* prologue end (size=4) */
> ldi r18,lo8(-1)
> sts crchi,r18
> sts crclo,r18
> .L3:
> ldi r24,lo8(1)
> rcall crcbit
> ldi r24,lo8(0)
> rcall crcbit
> rjmp .L3
> /* epilogue: frame size=0 */
> __stop_progIi__:
> rjmp __stop_progIi__
> /* epilogue end (size=1) */
> /* function main size 15 (10) */
> .Lfe2:
> .size main,.Lfe2-main
> .lcomm crchi,1
> .lcomm crclo,1
> /* File crc.c: code 54 = 0x0036 ( 48), prologues 4, epilogues 2
> */
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list
------------------------------------------------------------------
private: address@hidden
company: address@hidden