Keil Logo

C51: SUPPRESSING CALLS TO FUNCTION FROM COMMON CODE BLOCKS


Information in this article applies to:

  • C51 Version 7.02 or higher
  • CX51 Version 7.02 or higher

QUESTION

I'm using the highest compiler optimization levels that generates subroutines with common code blocks. However, my application requires that I leave specific function calls outside of common code blocks. How can I prevent a specific function call to be placed in a common code block?

ANSWER

You can apply the volatile attribute to a function to ensure that it is not called from common subroutine sequences. When the optimizer detects a volatile function, it avoids packing calls to that function into common code blocks. For example:

#pragma OPTIMIZE (9)

extern volatile void vol_func (int);
extern void reg_func (int);

int x;

void main (void)
{
x = 0;

vol_func (1);   vol_func (2);
reg_func (1);   reg_func (2);

x = 0x222;
x = 0;

vol_func (1);   vol_func (2);
reg_func (1);   reg_func (2);

while(1);
}

packs calls to reg_func but does not pack calls to vol_func.

             ; FUNCTION main (BEGIN)
                                           ; SOURCE LINE # 6
                                           ; SOURCE LINE # 7
                                           ; SOURCE LINE # 8
0000 E4                CLR     A
0001 F500        R     MOV     x,A
0003 F500        R     MOV     x+01H,A
                                           ; SOURCE LINE # 10
0005 7F01              MOV     R7,#01H
0007 FE                MOV     R6,A
0008 120000      E     LCALL   _vol_func
000B 7F02              MOV     R7,#02H
000D 7E00              MOV     R6,#00H
000F 120000      E     LCALL   _vol_func
                                           ; SOURCE LINE # 11
0012 120000      R     LCALL   L?0004
                                           ; SOURCE LINE # 13
0015 750002      R     MOV     x,#02H
0018 750022      R     MOV     x+01H,#022H
.
.
.

MORE INFORMATION

  • Refer to volatile in the Cx51 User's Guide.

SEE ALSO

Last Reviewed: Monday, July 18, 2005


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.