SECTION

Before you can start writing code you must define a section. This tells the assembler what kind of data follows and if it is code where to put it.

SECTION   "CoolStuff",ROMX

This switches to the section called "CoolStuff" (or creates it if it doesn't already exits) and it defines it as a code section. All sections within a sourcefile must be identified by a unique name.

Possible section types are as follows:

ROM0
A ROM section. Mapped to memory at $0000–$3fff.
ROMX
A banked ROM section. Mapped to memory at $4000–$7fff. Valid banks range from 1 to 511.
VRAM
A banked video RAM section. Mapped to memory at $8000–$9fff. Can only allocate memory, not fill it. Valid banks range from 0 to 1.
SRAM
A banked external (save) RAM section. Mapped to memory at $a000–$bfff. Can only allocate memory, not fill it. Valid banks range from 0 to 3.
WRAM0
A general-purpose RAM section. Mapped to memory at $c000–$cfff. Can only allocate memory, not fill it.
WRAMX
A banked general-purpose RAM section. Mapped to memory at $d000–$dfff. Can only allocate memory, not fill it. Valid banks range from 1 to 7.
HRAM
A high RAM section. Mapped to memory at $ff80–$fffe. Can only allocate memory, not fill it. NOTE WELL: if you use this method of allocating HRAM the assembler will NOT choose the short addressingmode in the LD instruction because the actual address calculation is done by the linker! If you find this undesirable you can use RSSET/RB/RW instead or use the LDIO mnemonic. The address calculation is then done by the assembler.

The following deprecated section names are aliases for some of the above sections:

HOME
Alias for ROM0.
CODE
DATA
Alias for ROMX.
BSS
Alias for WRAM0.

Due to quite a lot of emails requesting an ORG directive you can now add an address to the sectiontype for the Gameboy:

SECTION   "CoolStuff",ROM0[$1234]

This will force the section to address $1234. This also works with the other sectiontypes. For ROMX sections the linker will then place the section in any bank at the address you specify. If you also want to specify the bank you can do:

SECTION   "CoolStuff",ROMX[$4567],BANK[3]

And if you only want to force the section into a certain bank, and not it's position within the bank, that's also possible:

SECTION   "CoolStuff",ROMX,BANK[7]

HINT: If you think this is a lot of typing for doing a simple ORG type thing you can quite easily write an intelligent macro (called ORG for example) that uses \@ for the sectionname and determines correct sectiontype etc as arguments for SECTION

See also:


Last updated 18 July 1997 by Carsten Sorensen