shithub: rgbds

ref: 998cfe1bdd35229fa4623b543645c1bcfd462b88
dir: /doc/asm/section.htm/

View raw version
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>xAsm SECTION</title>
        <link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<h1>SECTION</h1>
<p>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.</p>
<pre>SECTION   "CoolStuff",ROMX</pre>
<p>This switches to the section called <b>"CoolStuff"</b> (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 <em>unique</em> name.</p>

<p>Possible section types are as follows:

<dl>
	<dt>ROM0</dt>
	<dd>A ROM section. Mapped to memory at $0000–$3fff.</dd>

	<dt>ROMX</dt>
	<dd>A banked ROM section. Mapped to memory at $4000–$7fff. Valid banks range from 1 to 511.</dd>

	<dt>VRAM</dt>
	<dd>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.</dd>

	<dt>SRAM</dt>
	<dd>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.</dd>

	<dt>WRAM0</dt>
	<dd>A general-purpose RAM section. Mapped to memory at $c000–$cfff. Can only allocate memory, not fill it.</dd>

	<dt>WRAMX</dt>
	<dd>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.</dd>

	<dt>HRAM</dt>
	<dd>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 <a href="rs.htm">RSSET/RB/RW</a> instead or use the LDIO mnemonic. The address calculation is then done by the assembler.</dd>
</dl>

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

<dl>
	<dt>HOME</dt>
	<dd>Alias for ROM0.</dd>

	<dt>CODE</dt>
	<dt>DATA</dt>
	<dd>Alias for ROMX.</dd>

	<dt>BSS</dt>
	<dd>Alias for WRAM0.</dd>
</dl>

<p>Due to quite a lot of emails requesting an ORG directive you can now add an address to the sectiontype for the Gameboy:</p>
<pre>SECTION   "CoolStuff",ROM0[$1234]</pre>
<p>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:</p>
<pre>SECTION   "CoolStuff",ROMX[$4567],BANK[3]</pre>
<p>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:</p>
<pre>SECTION   "CoolStuff",ROMX,BANK[7]</pre>
<p><strong>HINT:</strong> 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 <a href="expr_str.htm">\@</a> for the sectionname and determines correct sectiontype etc as arguments for SECTION</p>
<h1>See also:</h1>
<ul>
<li><a href="../link.htm">xLink</a> documentation
<li><a href="expr_int.htm">Integer and Boolean expressions</a>
<li><a href="expr_str.htm">String expressions, functions and formatting</a>
<li><a href="pops.htm">POPS and PUSHS:</a> The section stack.
</ul>
<hr>
<p>Last updated 18 July 1997 by <a href="mailto:[email protected]">Carsten Sorensen</a></p>
</body>
</html>