SPNU118Z September 1995 – March 2023 66AK2E05 , 66AK2H06 , 66AK2H12 , 66AK2H14 , AM1705 , AM1707 , AM1802 , AM1806 , AM1808 , AM1810 , AM5K2E04 , OMAP-L132 , OMAP-L137 , OMAP-L138 , SM470R1B1M-HT , TMS470R1A288 , TMS470R1A384 , TMS470R1A64 , TMS470R1B1M , TMS470R1B512 , TMS470R1B768
These directives associate portions of an assembly language program with the appropriate sections:
Chapter 12 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. |
.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.
1 ***************************************************
2 * Start assembling into the .text section *
3 ***************************************************
4 00000000 .text
5 00000000 00000001 .word 1,2
00000004 00000002
6 00000008 00000003 .word 3,4
0000000c 00000004
7
8 ***************************************************
9 * Start assembling into the .data section *
10 ***************************************************
11 00000000 .data
12 00000000 00000009 .word 9, 10
00000004 0000000A
13 00000008 0000000B .word 11, 12
0000000c 0000000C
14
15 **************************************************
16 * Start assembling into a named, *
17 * initialized section, var_defs *
18 **************************************************
19 00000000 .sect "var_defs"
20 00000000 00000011 .word 17, 18
00000004 00000012
21
22 **************************************************
23 * Resume assembling into the .data section *
24 **************************************************
25 00000010 .data
26 00000010 0000000D .word 13, 14
00000014 0000000E
27 00000000 .bss sym, 19 ; Reserve space in .bss
28 00000018 0000000F .word 15, 16 ; Still in .data
0000001c 00000010
29
30 **************************************************
31 * Resume assembling into the .text section *
32 **************************************************
33 00000010 .text
34 00000010 00000005 .word 5, 6
00000014 00000006
35 00000000 usym .usect "xy", 20 ; Reserve space in xy
36 00000018 00000007 .word 7, 8 ; Still in .text
0000001c 00000008