Keil Logo

USERCLASS Compiler Directive

Abbreviation

UCL

Arguments

(mspace = user_classname)

mspace refers to the default memory space used for the variable or function allocation and is explained in the table below:

mspace Description
UCODE program code; refers to the class CODE or ECODE depending on the ROM directive. When ROM(HUGE) is selected the program code is placed in the class ECODE; otherwise program code is placed in the class CODE.
CODE variables defined with the memory type code or program code when the ROM directive indicates SMALL, COMPACT, or LARGE. For program code you may use UCODE instead since this is independent of the ROM directive setting.
ECODE program code when the ROM directive indicates HUGE. To be independent of the ROM directive setting you may use UCODE instead.
DATA data variables located in the DATA class.
IDATA idata variables located in the IDATA class.
XDATA xdata variables located in the XDATA class.
XCONST const xdata variables located in the XDATA class.
NEAR near variables located in the EDATA class.
NCONST const near variables located in the NCONST class.
FAR far variables located in the HDATA class.
HUGE huge variables located in the HDATA class.
HCONST const huge variables located in the HCONST class.

user_classname is the name for a memory class. You can supply any valid identifier for a class name. If you specify default, C251 selects the default user class again.

Note

  • In contrast to the Cx51 Compiler variables with the static attribute that are defined inside a function are assigned to the default memory class. USERCLASS only affects variables that are defined at file level. Variables defined inside a function are assigned to the default user classes.
Default

Segments receive the default class name.

µVision

Options — C251 Compiler — Misc Controls.

Description

The USERCLASS directive assigns a user defined class name to a compiler generated segment. By default, C251 uses the basic class name for segment definitions. The user class name can be referred to at the L251 level to locate all segments with a class name, such as EDATA_NVRAM to a specific memory section.

See Also

ROM

Example
C251 UCL.C SRC

#pragma userclass (near = app1)
int    near    x1 [10];
int    near    x2 [10];

#pragma userclass (near = default)
int    near    y1 [10];
int    near    y2 [10];

#pragma userclass (far = app2)
int    far     x3 [10];
int    far     x4 [10];

#pragma userclass (ucode = t2code)
int test1 (int i1, int i2)  {
  return (i1 + i2 * 10);
}

The example above creates the following assembly source. Note that the program is translated with the setting ROM(HUGE) and therefore the program code is placed in the class ECODE_T2CODE.

                NAME UCL
  ?ED?APP1?UCL  SEGMENT  'EDATA_APP1'
  ?FA?APP2?UCL  SEGMENT  'HDATA_APP2'
?PR?T2CODE?UCL  SEGMENT  'ECODE_T2CODE'
       ?ED?UCL  SEGMENT  EDATA

     RSEG       ?ED?APP1?UCL
           x1:  DS  20
           x2:  DS  20

     RSEG       ?FA?APP2?UCL
           x3:  DS  20
           x4:  DS  20

     RSEG       ?ED?UCL
           y1:  DS  20
           y2:  DS  20
     RSEG       ?PR?T2CODE?UCL
        test1? PROC FAR;
---- Variable 'i2' assigned to Register 'WR4' ----
       MOV     WR2,WR6;
---- Variable 'i1' assigned to Register 'WR2' ----
; line 14:   return (i1 + i2 * 10);
       MOV     WR6,#0AH
       MUL     WR6,WR4
       ADD     WR6,WR2
; line 15: }
       ERET
       ENDP

       END
#pragma userclass (near=app1)

assigns the user class EDATA_APP1 to variables with memory space near which are then placed in the memory class EDATA by default. Therefore the arrays x1 and x2 are located in the memory class EDATA_APP1.

#pragma userclass (near=default)

resets the memory class for near variables to the compiler default.

  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.