Keil Logo

FUNCTIONS Compiler Directive

Abbreviation

FC

Arguments

Memory type and reentrant/static attribute.

Default

Static code generation in the default memory type.

µVision

Options — C251 Compiler — Memory Model — Use static memory for nonregister automatics.

Description

With the FUNCTIONS directive, the memory model and reentrant attribute can be changed. The syntax of this directive is:

FUNCTIONS ([fmodel, ] [attribute] )

The fmodel specifies the memory type used for non-register variables. The FUNCTIONS (fmodel) sub-control does not influence the pointer size. The following table describes the available options for fmodel. The specification of fmodel implies the static attribute.

fmodel Descrption
TINY, TY Use data memory for non-register automatics.
XTINY, XTY Use edata memory for non-register automatics.
SMALL, SM Use data memory for non-register automatics.
XSMALL, XSM Use edata memory for non-register automatics.
LARGE, LA Use xdata memory for non-register automatics.
PLM Use Intel PL/M-51 parameter passing via data memory, register parameters are never used.

The attribute specifies static or reentrant code generation. The available options are listed below:

attribute Descrption
static Use static memory for non-register automatic and parameter variables. The linker/locater overlays the static memory areas of functions when they do not call each other.
reentrant Use the 251 stack space for non-register automatic and parameter variables. mem_model has no influence on the variable placement and should be not specified together with reentrant.
Example

The following example is a source and code listing of various functions, each modified with #pragma functions. Note that the placement of local variables is affected. In case of reentrant functions the function name is mangled. The PLM function style provides an interface to programs written with Intel's PL/M-51. It implies parameter passing via data memory (static approach).

stmt  level    source
    1          typedef unsigned int    uint;
    2          typedef unsigned char  uchar;
    3
    4          #pragma functions (PLM)
    5          uint PlmFunc (uchar u1, uint n1)  {
    6   1        return (n1 + u1 + 10);
    7   1      }
    8
    9          #pragma functions (reentrant)
   10          uint XsmFunc (uchar u1, uint n1)  {
   11   1        return (n1 + u1 + 10);
   12   1      }
   13
   14          #pragma functions (XSMALL, static)
   15          uint XsmStat (uchar u1, uint n1)  {
   16   1        uchar  arr[10];
   17   1        for ( n1 = 0 ; n1 < 10 ; ++n1 )  {
   18   2          arr[n1] = 0x10;
   19   2        }
   20   1        return (n1 + u1 + 10);
   21   1      }
   22
   23          #pragma functions (reentrant)
   24          uint XsmRent (uchar u1, uint n1)  {
   25   1        uchar  arr[10];
   26   1        for ( n1 = 0 ; n1 < 10 ; ++n1 )  {
   27   2          arr[n1] = 0x10;
   28   2        }
   29   1        return (n1 + u1 + 10);
   30   1      }
;       FUNCTION PLMFUNC (BEGIN)
                ; SOURCE LINE # 5
                ; SOURCE LINE # 6
000000 E500        R  MOV      A,u1          ; A=R11
000002 0A3B           MOVZ     WR6,R11       ; A=R11
000004 2E3500      R  ADD      WR6,n1
000007 2E34000A       ADD      WR6,#0AH
                ; SOURCE LINE # 7
00000B 22             RET
;       FUNCTION PLMFUNC (END)

;       FUNCTION XsmFunc?_ (BEGIN)
        ; SOURCE LINE # 10
;---- Variable 'n1' assigned to Register 'WR6' ----
;---- Variable 'u1' assigned to Register 'R11' ----
                ; SOURCE LINE # 11
000000 0A2B           MOVZ     WR4,R11       ; A=R11
000002 2D32           ADD      WR6,WR4
000004 2E34000A       ADD      WR6,#0AH
                ; SOURCE LINE # 12
000008 22             RET
;       FUNCTION XsmFunc?_ (END)

;   FUNCTION XsmStat (BEGIN)
                ; SOURCE LINE # 15
000000 7D23           MOV      WR4,WR6
;---- Variable 'n1' assigned to Register 'WR4' ----
000002 7C7B           MOV      R7,R11        ; A=R11
;---- Variable 'u1' assigned to Register 'R7' ----
                        ; SOURCE LINE # 17
000004 6D22           XRL      WR4,WR4
        ?C0006:
                        ; SOURCE LINE # 18
000006 7410           MOV      A,#010H       ; A=R11
000008 19B20000    R  MOV      @WR4+arr,R11  ; A=R11
                        ; SOURCE LINE # 19
00000C 0B24           INC      WR4,#01H
00000E BE24000A       CMP      WR4,#0AH
000012 78F2           JNE      ?C0006
                        ; SOURCE LINE # 20
000014 0A37           MOVZ     WR6,R7
000016 2E34000A       ADD      WR6,#0AH
00001A 2E34000A       ADD      WR6,#0AH
                        ; SOURCE LINE # 21
00001E 22  RET
;       FUNCTION XsmStat (END)

;       FUNCTION XsmRent?_ (BEGIN)
                        ; SOURCE LINE # 24
000000 7D23           MOV      WR4,WR6
;---- Variable 'n1' assigned to Register 'WR4' ----
000002 7C7B           MOV      R7,R11        ; A=R11
;---- Variable 'u1' assigned to Register 'R7' ----
000004 2EF8000A       ADD      DR60,#0AH
                ; SOURCE LINE # 26
000008 6D22           XRL      WR4,WR4
        ?C0012:
                        ; SOURCE LINE # 27
00000A 7410           MOV      A,#010H       ; A=R11
00000C 7F0F           MOV      DR0,DR60
00000E 2E14FFF7       ADD      WR2,#0FFF7H
000012 2D12           ADD      WR2,WR4
000014 7A19B0         MOV      @WR2,R11      ; A=R11
                        ; SOURCE LINE # 28
000017 0B24           INC      WR4,#01H
000019 BE24000A       CMP      WR4,#0AH
00001D 78EB           JNE      ?C0012
                        ; SOURCE LINE # 29
00001F 0A37           MOVZ     WR6,R7
000021 2E34000A       ADD      WR6,#0AH
000025 2E34000A       ADD      WR6,#0AH
                        ; SOURCE LINE # 30
000029 9EF8000A       SUB      DR60,#0AH
00002D 22             RET
;       FUNCTION XsmRent?_ (END)
  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.