as: Sub-Sections

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