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

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

[avr-gcc-list] enum with 8 bit encoding


From: Carsten Beth
Subject: [avr-gcc-list] enum with 8 bit encoding
Date: Sun, 14 Apr 2002 13:57:12 +0200

Hi there!

Is it possible to force avr-gcc to use only 8 bit constants to code
eenumeration types?

In many cases it's a waste of space to use enums. For example I use the
following code to define communication symbols:

typedef enum
{
  set_state            = 's',
  send_eeprom          = 'm',
  change_eeprom        = 'l',
  send_det             = 'd',
  synchonization       = 'r',
  end_of_block         = 'e'
} t_symbol;

There are only 6 constants, so it should be possible to use a char for
coding, but avr-gcc uses int. Here is a short example of assembler code
produced to code a switch statement. r24/25 holds a value with type
t_symbol:

 590: 8d 2f        mov r24, r29
 592: 99 27        eor r25, r25            // waste
 594: 8c 36        cpi r24, 0x6C ; 108
 596: 91 05        cpc r25, r1             // waste
 598: 79 f1        breq .+94      ; 0x5f8
 59a: 8d 36        cpi r24, 0x6D ; 109
 59c: 91 05        cpc r25, r1             // waste
 59e: dc f4        brge .+54      ; 0x5d6
 5a0: 84 36        cpi r24, 0x64 ; 100
 5a2: 91 05        cpc r25, r1             // waste
 5a4: 91 f5        brne .+100     ; 0x60a



Yours sincerely,

        Carsten

avr-gcc-list at http://avr1.org



reply via email to

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