Include a file: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) No edit summary |
Puppydrum64 (talk | contribs) m (→{{header|6502 Assembly}}: added more examples and demonstrated the difference between include and incbin) |
||
Line 16: | Line 16: | ||
<lang 360asm> COPY member</lang> |
<lang 360asm> COPY member</lang> |
||
=={{header|6502 Assembly}}== |
=={{header|6502 Assembly}}== |
||
There are two different directives for including files: <code>include</code> and <code>incbin</code>. <code>include</code> is for code |
There are two different directives for including files: <code>include</code> and <code>incbin</code>. <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. |
||
For this example, the file "foo.txt" is a file containing only the following: <code>RTS</code> |
|||
<lang 6502asm>;main.asm |
|||
org $8000 |
|||
include "foo.txt" |
|||
;eof</lang> |
|||
A hexdump of the resulting machine code would look like this: |
|||
<pre> |
|||
HEXDUMP OF |
|||
$8000: 60 00 00 00 00 00 00 00 `....... |
|||
</pre> |
|||
Now compare it to the following: |
|||
<lang 6502asm>;main.asm |
|||
org $8000 |
|||
incbin "foo.txt" |
|||
;eof</lang> |
|||
<pre> |
|||
HEXDUMP OF |
|||
$8000: 52 54 53 00 00 00 00 00 RTS..... |
|||
</pre> |
|||
As you can see, when <code>incbin</code> was used the assembler made no attempt to translate the assembly mnemonic into machine instructions. |
|||
Unlike high-level languages, the location of the <code>include</code> or <code>incbin</code> statement matters. This of course depends on the assembler, but generally speaking, there are a few limitations: |
|||
* If you <code>include</code> a macro <i>after</i> that macro is used in your source code, the assembler may raise an error message. If your macros are always before your code this isn't a problem. |
* If you <code>include</code> a macro <i>after</i> that macro is used in your source code, the assembler may raise an error message. If your macros are always before your code this isn't a problem. |
||
Line 39: | Line 67: | ||
include "math.asm" |
include "math.asm" |
||
;eof</lang> |
;eof</lang> |
||
=={{header|AArch64 Assembly}}== |
=={{header|AArch64 Assembly}}== |