Keil Logo

SECTION Assembler Statement

Arguments
section SECTION type <[>alignment<]> <[>combine<]> <[>'classname'<]>
.
.
.
section ENDS
Description

The SECTION statement defines a logical memory section which contains program code or data (all code and data in your program are stored in sections). Sections allow you to group related code or data. Code sections are stored in segments while data sections are stored in pages (that are 16K Bytes in size). If several sections in a source module have the same name, the assembler treats them as a single section consisting of multiple partial sections.

Refer to Sections, Classes, and Groups in the L166 Linker User's Guide for more information.

The MCU has two fundamental operating modes which affect sections:

  • Segmented Mode:
    In this mode, the MCU addresses up to 16M Bytes of memory.
  • Non-Segmented Mode:
    In this mode, the MCU addresses up to 64K Bytes of memory. All references are NEAR because DPPs (data page pointers) are loaded only once at startup. No segmented calls are required.

To create a section, you must first specify the section name. To end a section, you must specify the section name using the ENDS statement.

Section Type

Each section has a required type which may be one of the following:

  • BIT
    Sections of this type are mapped into the bit-addressable space located in on-chip RAM at addresses 0FD00h-0FDFFh. In BIT sections, the location counter increments in bit units.
  • CODE
    Sections of this type are mapped into segments. In Non-Segmented Mode, 64K Bytes (0000h-0FFFFh) of memory may be addressed. In Segmented Mode, CODE sections may be located anywhere in the 16M Byte address space.
  • DATA, CONST
    Sections of this type are mapped into 16K pages. In Non-Segmented Mode, pages may reside in the first 64K Bytes (0000h-0FFFFh) of memory. In Segmented Mode, pages may be located anywhere in the 16M Byte address space.
  • HDATA, HCONST
    Sections of this type are mapped into 64K segments.
  • XDATA, XCONST
    Sections of this type have no size or memory limitations. The can be anywhere in the 16M Byte address space.

Section Alignment

Sections may have an optional alignment type that is used by the linker when combining or locating sections. If no alignment type is specified, the default alignment is derived from the section type (BIT alignment for BIT sections, WORD alignment for CODE and DATA sections). The alignment specified must be one of the following:

  • BIT
    This alignment type specifies that the section is combined or located at a bit boundary. It allows the linker to combine bit sections without leaving gaps.
  • BYTE
    This alignment type specifies that the section is combined or located at a byte boundary. Sections that contain word variables or program code may not be aligned to a byte boundary. This restriction is imposed because word accesses must be at even byte boundaries. Word accesses on odd boundaries cause an execution trap.
  • WORD
    This alignment type specifies that the section is combined or located at a word boundary. The section begins at an even address.
  • DWORD
    This alignment type specifies that the section is combined or located at a double word boundary. The section begins at an address that is a multiple of four.
  • PAGE
    This alignment type specifies that the section is combined or located at a 16K Byte page boundary. Pages begin at addresses that are a multiple of 16K. For example, 0000h, 4000h, 8000h, 0C000, 10000h, and so on.
  • SEGMENT
    This alignment type specifies that the section is combined or located at a 64K Byte segment boundary. Segments begin at addresses that are a multiple of 64K. For example, 000000h, 010000h, 020000h, 030000h, and so on.
  • BITADDRESSABLE
    This alignment type specifies that the section is combined or located at a word boundary (the section begins at an even address) in bit-addressable on-chip memory (0FD00h-0FDFFh).
  • PECADDRESSABLE
    This alignment type specifies that the section is combined or located at a word boundary (the section begins at an even address) in on-chip memory (0FDE0h-0FDFFh).

Combining Sections

Sections may have an optional combine type that specifies, to the linker, how sections are combined with sections from other modules to form a page or a segment in memory. If no combine type is specified, the default PRIVATE combine type is used. The combine type specified must be one of the following:

  • PRIVATE
    This combine type specifies that the section may not be combined with other sections. This only applies to sections from other modules. Sections from the same module are combined as normal.
  • PUBLIC
    This combine type specifies that all sections with the same name are combined into a single section. That section is visible to a single TGROUP.
  • GLOBAL
    This combine type specifies that all sections with the same name are combined into a single section. That section is visible to the entire application — beyond TGROUPs.
  • COMMON
    This combine type specifies that all COMMON sections with the same name are overlaid in a single section. The combined sections all begin at the same address. The length of the overlaid section is the length of the largest COMMON section.
  • SYSSTACK
    This combine type specifies that all sections with the same name are combined into a single section. The linker locates that section in on-chip memory and uses it for the system stack. The system stack is accessed using the stack pointer (SP) which is accessed by the CALL, PUSH, POP, and SCTX instructions.
  • USRSTACK
    This combine type specifies that all sections with the same name are combined into a single section (which is visible to a single TGROUP.). The linker locates that section in memory and uses it for the user stack (for function arguments and local variables). The user stack is accessed using a DPP register and offset and may be a total of 16K Bytes in length.
  • GLBUSRSTACK
    This combine type specifies that all sections with the same name are combined into a single section (which is visible to the entire application — beyond TGROUPs). The linker locates that section in memory and uses it for the user stack (for function arguments and local variables). The user stack is accessed using a DPP register and offset and may be a total of 16K Bytes in length.
  • AT expression
    This combine type specifies that the section is located at the absolute address specified by expression (which must evaluate to a constant with no forward references). The address must be valid for the specified section type and alignment type (for example, a bit-addressable section must be located in on-chip memory). The AT attribute implies that the section may not be combined with other sections. The assembler verifies the section type, alignment type, and CPU mode for these types of section combine types.

Class Name

The 'classname' specifies a class name for the section. The class name may be used by the linker to locate multiple sections in a general memory area (like RAM, ROM, FLASH, and so on). Refer to Classes in the L166 Linker User's Guide for more information.

See Also

ENDS

Example

A section may be opened and closed multiple times. All partial sections are combined into a single section. When a section is reopened, the attributes (with the exception of section type) need not be specified. If the attributes are specified, they may not specify types different than previous definitions.

The following example shows multiple section definitions using the same name. One section generates an error because of a redefined attribute.

          1     D100    SECTION DATA BITADDRESSABLE
0000      2       V1    DSW     1 ; reserve one word of storage
          3     D100    ENDS
          4
          5     D100    SECTION DATA
0002      6       V2    DSW     1 ; reserve one word of storage
          7     D100    ENDS
          8
          9     ; The above sections are equivalent to the following:
         10
         11     ;D100   SECTION DATA BITADDRESSABLE
         12     ;  V1   DSW     1 ; reserve one word of storage
         13     ;  V2   DSW     1 ; reserve one word of storage
         14     ;D100   ENDS
         15
         16     ; Changing the Alignment Type Causes an Error.
         17
         18     D100    SECTION DATA WORD
*** _________________________________^
*** ERROR #31, LINE #18, REDEFINITION: 'ALIGN TYPE'
0008     19       V3    DSW     1 ; reserve one word of storage
         20     D100    ENDS
         21
         22             END

You may nest section definitions. Typically, sections are nested to define data sections in code sections. Code sections may not be nested. While you may syntactically nest section definitions, the sections are still treated as independent sections or partial sections and are combined by the assembler.

Up to ten nested sections are allowed. Nested sections must be closed inside out (the innermost section must be closed first).

The following example shows a nested section definition with an absolute data section nested within a relocatable data section:

          1       D100    SECTION DATA BITADDRESSABLE
0000      2         V1    DSW     1    ; Relocatable Word
          3         D200  SECTION DATA AT 4000H
0000      4           A1  DSW     1    ; Absolute Word at 4000h
0002      5           A2  DSW     1    ; Absolute Word at 4002h
          6         D200  ENDS         ; Close Section D200
0002      7         V2    DSW     1    ; Resume Section D100
          8       D100    ENDS
  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.