Keil™, An ARM® Company

Cx51 User's Guide

NOAREGS Compiler Directive

Abbreviation NOAR
Arguments None.
Default AREGS
µVision Options — C51 — Don’t use absolute register accesses.
Description 

The NOAREGS directive disables absolute register addressing for registers R0-R7. Functions compiled with NOAREGS are register bank independent and work in any register bank. This directive may be used for functions that are called from other functions using different register banks.

NOTE

  • Though they may be defined several times in a program, the AREGS and NOAREGS options are valid only when defined outside of a function declaration.
See Also AREGS, REGISTERBANK
Example 

The following is a source and code listing which uses both NOAREGS and AREGS.

stmt level    source
1          extern char func ();
2          char k;
3
4          #pragma NOAREGS
5          noaregfunc ()  {
6   1        k = func () + func ();
7   1      }
8
9          #pragma AREGS
10          aregfunc ()  {
11  1        k = func () + func ();
12  1      }

; FUNCTION noaregfunc (BEGIN)
		; SOURCE LINE # 6
0000 120000 E   LCALL func
0003 EF         MOV   A,R7
0004 C0E0       PUSH  ACC
0006 120000 E   LCALL func
0009 D0E0       POP   ACC
000B 2F         ADD   A,R7
000C F500   R   MOV   k,A
		; SOURCE LINE # 7
000E 22         RET
	; FUNCTION noaregfunc (END)
	; FUNCTION aregfunc (BEGIN)
		; SOURCE LINE # 11
0000 120000  E  LCALL func
0003 C007       PUSH  AR7
0005 120000  E  LCALL func
0008 D0E0       POP   ACC
000A 2F         ADD   A,R7
000B F500    R  MOV   k,A
		; SOURCE LINE # 12
000D 22         RET
	; FUNCTION aregfunc (END)

Note the different methods of saving R7 on the stack. The code generated for the function noaregfunc is:

MOV  A,R7
PUSH ACC

While the code for the aregfunc function is:

PUSH AR7

Related Knowledgebase Articles