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",CODE

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.

Section types
Name Function
CODE A code section. The linker decides where to put this. For the Gameboy it also decides which bank to put it in except #0 (the HOME bank).
DATA Really just a synonym for CODE.
BSS This section is for variables. For the Gameboy it will be placed where the Gameboy RAM is.
HOME Gameboy ONLY: A code section that will be placed in Gameboy bank #0.
VRAM Gameboy ONLY: This section is for allocating VRAM and will be placed where the Gameboy VRAM is.
HRAM Gameboy ONLY: This section is for allocating variables in the high RAM area ($FF80-$FFFE) and will be placed there. Suggested by Jens Ch. Restemeier. 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.

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",HOME[$1234]

This will force the section to address $1234. This also works with the other sectiontypes. For CODE/DATA 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",DATA[$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",CODE,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