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

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

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


From: Jonathan Blanchard
Subject: [avr-gcc-list] Checking carry flag and Rotate operation in C.
Date: Sun, 15 Jun 2008 20:42:41 -0300

Hi,

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




reply via email to

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