Keil Logo

INTPROMOTE Compiler Directive

Abbreviation

IP

Arguments

None.

Default

INTPROMOTE

µVision

Options — C51 — Enable ANSI integer promotion rules.

Description

The INTPROMOTE directive enables ANSI integer promotion rules. Expressions used in if statements are promoted from smaller types to integer expressions before comparison. This allows Microsoft C and Borland C programs to be ported to the C51 Compiler with fewer modifications.

Since the 8051 is an 8-bit processor use of the INTPROMOTE directive may generate less efficient code in some applications.

See Also

ENUMINT, NOINTPROMOTE

Example
C51 SAMPLE.C INTPROMOTE
#pragma intpromote
C51 SAMPLE.C NOINTPROMOTE

The following example:

stmt lvl  source
1        char c;
2        unsigned char  c1,c2;
3        int  i;
4
5        main ()  {
6  1       if (c == 0xff) c = 0;    /* never true! */
7  1       if (c == -1) c = 1;      /* works */
8  1       i = c + 5;
9  1       if (c1 < c2 +4) c1 = 0;
10 1     }

demonstrates code generated using both the INTPROMOTE and NOINTPROMOTE control directives.

Code Generated
with INTPROMOTE
        ; FUNCTION main (BEGIN)
                ; SOURCE LINE # 6
0000 AF00         MOV  R7,c
0002 EF           MOV  A,R7
0003 33           RLC  A
0004 95E0         SUBB A,ACC
0006 FE           MOV  R6,A
0007 EF           MOV  A,R7
0008 F4           CPL  A
0009 4E           ORL  A,R6
000A 7002         JNZ  ?C0001
000C F500         MOV  c,A
000E         ?C0001:

                ; SOURCE LINE # 7
000E E500         MOV  A,c
0010 B4FF03       CJNE A,#0FFH,?C0002
0013 750001       MOV  c,#01H
0016         ?C0002:

                ; SOURCE LINE # 8
0016 AF00         MOV  R7,c
0018 EF           MOV  A,R7
0019 33           RLC  A
001A 95E0         SUBB A,ACC
001C FE           MOV  R6,A
001D EF           MOV  A,R7
001E 2405         ADD  A,#05H
0020 F500         MOV  i+01H,A
0022 E4           CLR  A
0023 3E           ADDC A,R6
0024 F500         MOV  i,A

                ; SOURCE LINE # 9
0026 E500         MOV  A,c2
0028 2404         ADD  A,#04H
002A FF           MOV  R7,A
002B E4           CLR  A
002C 33           RLC  A
002D FE           MOV  R6,A
002E C3           CLR  C
002F E500         MOV  A,c1
0031 9F           SUBB A,R7
0032 EE           MOV  A,R6
0033 6480         XRL  A,#080H
0035 F8           MOV  R0,A
0036 7480         MOV  A,#080H
0038 98           SUBB A,R0
0039 5003         JNC  ?C0004
003B E4           CLR  A
003C F500         MOV  c1,A

                ; SOURCE LINE # 10
003E            ?C0004:
003E 22           RET
        ; FUNCTION main (END)

Code Size: 63 Bytes
Code Generated
with NOINTPROMOTE
        ; FUNCTION main (BEGIN)
                ; SOURCE LINE # 6
0000 AF00          MOV  R7,c
0002 EF            MOV  A,R7
0003 33            RLC  A
0004 95E0          SUBB A,ACC
0006 FE            MOV  R6,A
0007 EF            MOV  A,R7
0008 F4            CPL  A
0009 4E            ORL  A,R6
000A 7002          JNZ  ?C0001
000C F500          MOV  c,A
000E          ?C0001:

                ; SOURCE LINE # 7
000E E500          MOV  A,c
0010 B4FF03        CJNE A,#0FFH,?C0002
0013 750001        MOV  c,#01H
0016         ?C0002:

                ; SOURCE LINE # 8
0016 E500          MOV  A,c
0018 2405          ADD  A,#05H
001A FF            MOV  R7,A
001B 33            RLC  A
001C 95E0          SUBB A,ACC
001E F500          MOV  i,A
0020 8F00          MOV  i+01H,R7





                ; SOURCE LINE # 9
0022 E500          MOV  A,c2
0024 2404          ADD  A,#04H
0026 FF            MOV  R7,A
0027 E500          MOV  A,c1
0029 C3            CLR  C
002A 9F            SUBB A,R7
002B 5003          JNC  ?C0004
002D E4            CLR  A
002E F500          MOV  c1,A









                ; SOURCE LINE # 10
0030          ?C0004:
0030 22            RET
        ; FUNCTION main (END)

Code Size: 49 Bytes

Related Knowledgebase Articles

  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.