Keil Logo

C51: INTEGER PROMOTION


Information in this article applies to:

  • C51 Version 5.50a
  • C51 Version 6.03

SYMPTOMS

I have written the following program that performs operations using unsigned chars.

void Test (void)
{
unsigned char Bob;
unsigned char Sally;
unsigned char Tom;
unsigned char Result;

Sally = Bob + 3;

if (( Tom + 2) == 5)
  {
  Result = 0 ;
  }
}

The code that's generated performs these operations in integers (16 bits).


             ; FUNCTION SpecialTest (BEGIN)
                                           ; SOURCE LINE # 7
                                           ; SOURCE LINE # 8
                                           ; SOURCE LINE # 14
0000 E500        R     MOV     A,Bob
0002 2403              ADD     A,#03H
0004 F500        R     MOV     Sally,A
                                           ; SOURCE LINE # 16
0006 E500        R     MOV     A,Tom
0008 2402              ADD     A,#02H
000A FF                MOV     R7,A
000B E4                CLR     A
000C 33                RLC     A
000D FE                MOV     R6,A
000E EF                MOV     A,R7
000F 6405              XRL     A,#05H
0011 4E                ORL     A,R6
0012 7002              JNZ     ?C0002
                                           ; SOURCE LINE # 17
                                           ; SOURCE LINE # 18
0014 F500        R     MOV     Result,A
                                           ; SOURCE LINE # 19
                                           ; SOURCE LINE # 20
0016         ?C0002:
0016 22                RET

What causes that?

CAUSE

This is caused by the ANSI integer promotion rules that the Keil C51 compiler observes. These rules are defined by the ANSI C Specification.

RESOLUTION

ANSI integer promotion rules are used by default. However, you may disable them by unselecting this option in the C51 compiler options (in µVision2) or from the command line with the NOINTPROMOTE directive.

The resulting output is what you will get when you do that.

                                           ; SOURCE LINE # 13
0000 E500        R     MOV     A,Bob
0002 2403              ADD     A,#03H
0004 F500        R     MOV     Sally,A
                                           ; SOURCE LINE # 15
0006 E500        R     MOV     A,Tom
0008 2402              ADD     A,#02H
000A FF                MOV     R7,A
000B BF0503            CJNE    R7,#05H,?C0003
                                           ; SOURCE LINE # 16
                                           ; SOURCE LINE # 17
000E E4                CLR     A
000F F500        R     MOV     Result,A
                                           ; SOURCE LINE # 18
                                           ; SOURCE LINE # 19
0011         ?C0003:
0011 22                RET

SEE ALSO

Last Reviewed: Monday, April 16, 2001


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.