SPRU513Y August 2001 – June 2022 SM320F28335-EP
These directives associate portions of an assembly language program with the appropriate sections:
Chapter 3 discusses these sections in detail.
The example that follows 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 this example 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. |
.usect | reserves 19 words |
xy | reserves 20 words. |
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.
1 ***************************************************
2 * Start assembling into the .text section *
3 ***************************************************
4 000000 .text
5 000000 0001 .word 1, 2
000001 0002
6 000002 0003 .word 3, 4
000003 0004
7
8 ***************************************************
9 * Start assembling into the .data section *
10 ***************************************************
11 000000 .data
12 000000 0009 .word 9, 10
000001 000A
13 000002 000B .word 11, 12
000003 000C
14
15 ***************************************************
16 * Start assembling into a named, *
17 * initialized section, var_defs *
18 ***************************************************
19 000000 .sect "var_defs"
20 000000 0011 .word 17, 18
000001 0012
21
22 ***************************************************
23 * Resume assembling into the .data section *
24 ***************************************************
25 000004 .data
26 000004 000D .word 13, 14
000005 000E
27 000000 sym .usect ".ebss", 19 ; Reserve space in .ebss
28 000006 000F .word 15, 16 ; Still in .data
000007 0010
29
30 ***************************************************
31 * Resume assembling into the .text section *
32 ***************************************************
33 000004 .text
34 000004 0005 .word 5, 6
000005 0006
35 000000 usym .usect "xy", 20 ; Reserve space in xy
36 000006 0007 .word 7, 8 ; Still in .text
37 000007 0008