Assembler Directives - SECTION

SECTION - This directive causes the program counter to be restored to the address following the last location allocated in the indicated section (or to zero if used for the first time). The ORG directive may be used within a section, at any time, to set the current program location. The assembler does not check for overlapping sections. The section directive provides a convenient way of separating code from data within a program.

Usage:
[label] SECTION [<number>]

> <number> must be in the range 0..15. No section numbers are reserved in any way. By default, the assembler will begin with section 0. Labels may be used for section numbers. If no section number is specified then a label is required and will be set to the value of the current section (0..15).

CODE EQU 0
DATA EQU 1
SECTION DATA
ORG $2000
msg1 DC.B 'Hello World',$d,$a,0
SECTION CODE
ORG $1000
<code>
SECTION DATA
msg2 DC.B 'EASy68K Rules!',$d,$a,0

Macros may be written to change sections and restore the previous section as shown in the following example:

DATA EQU 0
CODE EQU 1
MAC1 MACRO
SECT\@ SECTION
SECTION DATA
DC.B 'Hello World.'
SECTION SECT\@
ENDM

It is also possible to write a macro that modifies its behavior using conditional assembly based upon the section it is in when invoked as shown in the following example:

DATA EQU 0
CODE EQU 1
MAC2 MACRO
SECT\@ SECTION
IFEQ SECT\@-CODE
NOP
ENDC
IFEQ SECT\@-DATA
DC.B 'Greetings'
ENDC
ENDM

See Macro Assembly for more help on writing macros.