Having built a program from a set of sections it is usually necessary to specify how these sections should be layed out in the target system. The .group statement allows sections to be grouped together into units and for the order of the sections to be defined within the groups. Multiple groups overlay each other.e.g. .group group1, sect1, sect2, sect3, sect4 ; group 1 .group group2, sectA, sectB ; group 2 .group group3, sectW, sectX, sectY ; group 3Here group 1 consists of all code and data belonging to section sect1 then all code and data belonging to section sect2 then all code and data belonging to section sect3 then all code and data belonging to section sect4
e.g. .sect sect2 .data .db "sect2 item 10" .db "sect2 item 9" .sect sect1 .data .org 20 .db "sect1 item 1" .db "sect1 item 2" .sect sect4 .data .db "sect4 item 1" .db "sect4 item 2" .sect sect2 .db "sect2 item 5" .sect sect1 .db "sect1 item 3" .sect sect3 .data .db "sect3 item 1" .db "sect3 item 2" .sect sect2 .db "sect2 item 7"would generate the equivalent group.db "sect1 item 1" .db "sect1 item 2" .db "sect1 item 3" .db "sect2 item 10" .db "sect2 item 9" .db "sect2 item 5" .db "sect2 item 7" .db "sect3 item 1" .db "sect3 item 2" .db "sect4 item 1" .db "sect4 item 2"Group 1 would start at absolute address 20 due to the origin statement used at the begining of section sect1Group 2 would (in the absence of any origin statements) begin at absolute address 0 and group 3 would (in the absence of any origin statements) also begin at absolute address 0.
The three groups are overlaid one on top of the other. Using groups in this way allows programs to be easily built for targets that have seperate code and data spaces or that need to locate code or data in banked memory.
Macros that manipulate sections will typically need to restore the original section before completing. This can be done by saveing the current section name in an assemler variable, performing whatever section manipulation is necessary and then restoring the section from the assembler variable to which it was originally saved.
e.g. foo .macro arg1, arg2, arg3 var .set SECT_NAME($) .sect fred .db arg1, arg2, arg3 .sect var .endm