ARM Technical Support Knowledge Articles

SUPPRESSING CALLS TO FUNCTION FROM COMMON CODE BLOCKS

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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

SEE ALSO

Article last edited on: 2005-07-18 18:24:18

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential