You may have separate groups of data in named sections that you want to end up near to each other in the object file, even though they are not contiguous in the assembler source. the assembler allows you to use subsections for this purpose. Within each section, there can be numbered subsections with values from 0 to 8192. Objects assembled into the same subsection go into the object file together with other objects in the same subsection. For example, a compiler might want to store constants in the text section, but might not want to have them interspersed with the program being assembled. In this case, the compiler could issue a “.text 0” before each section of code being output, and a “.text 1” before each group of constants being output.
Subsections are optional. If you do not use subsections, everything goes in subsection number zero.
Each subsection is zero-padded up to a multiple of four bytes.
Subsections appear in your object file in numeric order, lowest numbered to highest. (All this to be compatible with other people's assemblers.) The object file contains no representation of subsections; the linker and other programs that manipulate object files see no trace of them. They just see all your text subsections as a text section, and all your data subsections as a data section.
To specify which subsection you want subsequent statements assembled into, use a numeric argument to specify it, in a “.text expression” or a “.data expression” statement. When generating COFF output, you can also use an extra subsection argument with arbitrary named sections: “.section name, expression”. Expression should be an absolute expression. (See Chapter 28.) If you just say “.text” then “.text 0” is assumed. Likewise “.data” means “.data 0”. Assembly begins in text 0. For instance:
.text 0 # The default subsection is text 0 anyway. .ascii "This lives in the first text subsection. *" .text 1 .ascii "But this lives in the second text subsection." .data 0 .ascii "This lives in the data section," .ascii "in the first data subsection." .text 0 .ascii "This lives in the first text section," .ascii "immediately following the asterisk (*)."
Each section has a location counter incremented by one for every byte assembled into that section. Because subsections are merely a convenience restricted to the assembler there is no concept of a subsection location counter. There is no way to directly manipulate a location counter—but the .align directive changes it, and any label definition captures its current value. The location counter of the section where statements are being assembled is said to be the active location counter.