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

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

[avr-gcc-list] Byte values promted to int when during compare


From: Lars Jeppesen (address@hidden)
Subject: [avr-gcc-list] Byte values promted to int when during compare
Date: Thu, 24 Jun 2004 10:03:22 +0200

Hi,

If I make the following code:

unsigned char A;
unsigned char B;

static unsigned char Test_func()
{
        // TEST TEST    
        if ( (unsigned char)((unsigned char)A & (unsigned char)15) != (unsigned 
char)B )
                TX1_State = 12;
}


The generated code look like this:
(With GCC 3.3.1 and -Os, also tryed with -O2,-O3 with the same result))

        if ( (unsigned char)((unsigned char)A & (unsigned char)15) != (unsigned 
char)B )
    1fae:       80 91 b0 03     lds     r24, 0x03B0
    1fb2:       28 2f           mov     r18, r24
    1fb4:       33 27           eor     r19, r19
    1fb6:       2f 70           andi    r18, 0x0F       ; 15
    1fb8:       30 70           andi    r19, 0x00       ; 0
    1fba:       80 91 b4 03     lds     r24, 0x03B4
    1fbe:       99 27           eor     r25, r25
    1fc0:       28 17           cp      r18, r24
    1fc2:       39 07           cpc     r19, r25
    1fc4:       19 f0           breq    .+6             ; 0x1fcc
                TX1_State = 12;
    1fc6:       8c e0           ldi     r24, 0x0C       ; 12
    1fc8:       80 93 5c 01     sts     0x015C, r24


It seems that A is promoted to int before the binary & operation ?
But why ?

A line like this.

A = B & 15;

Compiles correctly to 3 assembler lines.



Best regards
  Lars Jeppesen



reply via email to

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