Include a file: Difference between revisions

m
(Added a Scheme implementation.)
Line 2,481:
* <code>include</code> is for assembly code that will be converted to machine code that the computer can run.
* <code>incbin</code> is for binary data such as graphics, which the assembler will convert as-is to binary and does not attempt to translate it into machine code.
 
It's important to note that, unlike in high-level languages, WHERE your include/incbin statements are located relative to your other code matters. Placing it incorrectly can cause execution to "fall into" your included files when you didn't intend it to happen.
 
 
What ''not'' to do:
<lang z80>org &1000
include "\source\mathLibrary.asm"
main:
ld a,&42
ret</lang>
 
In assembly, the order you arrange your code is typically the same as its layout in memory, unless you're using a linker. In the above example, execution will begin at the ORG directive and "fall through" into your math Library, rather than starting at main. Unless your program has a header that jumps to main (something that [[C]] generates for you automatically), you're going to have some undesired effects if you don't "trap" the program counter.
 
The right way:
<lang z80>org &1000
main:
ld a,&42
ret
include "\source\mathLibrary.asm"</lang>
 
You'll have to take this with a grain of salt, as it's hardware-dependent (the above was for Amstrad CPC or other similar home computers where your program is CALLed from BASIC.) If you're defining your own ROM header for something like Game Boy things will be a bit different.
 
=={{header|zkl}}==
1,489

edits