5.2 Directives that Define Sections
These directives associate portions of an assembly language program with the appropriate sections:
- The .bss directive reserves space in the .bss section for uninitialized variables.
- The .data directive identifies portions of code in the .data section. The .data section usually contains initialized data.
- The .intvec directive creates an interrupt vector entry that points to an interrupt routine name.
- The .retain directive can be used to indicate that the current or specified section must be included in the linked output. Thus even if no other sections included in the link reference the current or specified section, it is still included in the link.
- The .retainrefs directive can be used to force sections that refer to the specified section. This is useful in the case of interrupt vectors.
- The .sect directive defines an initialized named section and associates subsequent code or data with that section. A section defined with .sect can contain code or data.
- The .text directive identifies portions of code in the .text section. The .text section usually contains executable code.
- The .usect directive reserves space in an uninitialized named section. The .usect directive is similar to the .bss directive, but it allows you to reserve space separately from the .bss section.
Section 2 discusses these sections in detail.
Example 1 shows how you can use sections directives to associate code and data with the proper sections. This is an output listing; column 1 shows line numbers, and column 2 shows the SPC values. (Each section has its own program counter, or SPC.) When code is first placed in a section, its SPC equals 0. When you resume assembling into a section after other code is assembled, the section's SPC resumes counting as if there had been no intervening code.
The directives in Example 1 perform the following tasks:
.text |
initializes words with the values 1, 2, 3, 4, 5, 6, 7, and 8. |
.data |
initializes words with the values 9, 10, 11, 12, 13, 14, 15, and 16. |
var_defs |
initializes words with the values 17 and 18. |
.bss |
reserves 19 bytes. |
xy |
reserves 20 bytes. |
The .bss and .usect directives do not end the current section or begin new sections; they reserve the specified amount of space, and then the assembler resumes assembling code or data into the current section.