ARM Technical Support Knowledge Articles

CHANGING OPTIMIZER LEVEL FOR A SINGLE FUNCTION

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

I'm using optimizer level 9 (Common Block Subroutines) and code that accesses the timed access protected SFRs (on parts like the Dallas 320, 520, 530, and 390) is replaced by subroutines. This causes the timed access to fail. For example, the following C code:

void TimeAccess (void)  {
  EA = 0;
  TA = 0xAA; TA = 0x55;
  RTCC = 1;
  TA = 0xAA; TA = 0x55;
  TRIM |= 0x80;
  TA = 0xAA; TA = 0x55;
  TRIM |= 0x40;
  EA = 1;
}

is compiled to the following:

             ; FUNCTION Com0005 (BEGIN)
0000         L?0006:
0000         L?0007:
0000 75C7AA            MOV     TA,#0AAH
0003 75C755            MOV     TA,#055H
0006 22                RET
             ; FUNCTION Com0005 (END)

             ; FUNCTION TimeAccess (BEGIN)
0000 C2AF              CLR     EA
0002 120000      R     LCALL   L?0006
0005 75F901            MOV     RTCC,#01H
0008 120000      R     LCALL   L?0006
000B 439680            ORL     TRIM,#080H
000E 120000      R     LCALL   L?0007
0011 439640            ORL     TRIM,#040H
0014 D2AF              SETB    EA
0016 22                RET
             ; FUNCTION TimeAccess (END)

If I compile with optimization level 8 or lower, this problem goes away, however, my program is then too big. Is there a way to change optimizer levels for just one function?

ANSWER

Yes. The Keil C51 Compiler allows you to specify the optimization level on a function-by-function basis. You may change the optimization level for critical functions as shown below:

#pragma SAVE        // save current optimization level
#pragma OPTIMIZE(8) // prevent common subroutine optimization

void TimeAccess (void)  {
  EA = 0;
  TA = 0xAA; TA = 0x55;
  RTCC = 1;
  TA = 0xAA; TA = 0x55;
  TRIM |= 0x80;
  TA = 0xAA; TA = 0x55;
  TRIM |= 0x40;
  EA = 1;
}

#pragma RESTORE    // restore previous optimization level

SEE ALSO

Article last edited on: 2005-11-28 10:45:04

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