[Top][All Lists]

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

Re: [avr-gcc-list] Checking carry flag and Rotate operation in C.

From: Andy H
Subject: Re: [avr-gcc-list] Checking carry flag and Rotate operation in C.
Date: Sun, 15 Jun 2008 20:45:00 -0400
User-agent: Thunderbird (Windows/20080421)

The simple answer us that you cant. Thougg we could do with this in library and/or gcc patterns (builtin rotate)

This is close:

unsigned char foo(unsigned char b)
if (b & 128)
   b  <<= 1;
   b ^= 0b00011101;
return b;

unsigned char bar(unsigned char b)
if (b & 128)
   b ^= 0b0001110;
   b <<= 1;
   b |= 1;
return b;

Jonathan Blanchard wrote:

I got two question about programming with AVR-GCC. Both are related to
finding a way to generate a specific output in assembler.

First, how do you create the rotate operation in C. Specifically how
can the ROL and ROR can be generated.

Secondly I have this piece of code where b is a 16 bit unsigned integer :

        b = b << 1;
        if( b & 256 )
            b = b ^ 0b100011101;

To optimize that I only need to check if b overflow at the left shift
operation by checking the carry flag. I'm trying to find a way to do
that in C. Right now I'm using the following piece of inline assembly
to do the trick :

        asm volatile(

                    "LSL %0     \n\t"
                    "BRCC 1f    \n\t"
                    "EOR %0, %1 \n\t"
                "1:""           \n\t"
                    :"+d" (b)
                    :"r"  (PPoly)

In this last piece of code b is a 8 bit unsigned integer and PPoly is
a 8 bit unsigned integer with the value 0b00011101. I'm just curious
to know if it's possible to achieve the same result only by using C.

Jonathan Blanchard

AVR-GCC-list mailing list

reply via email to

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