Pragmatic directives: Difference between revisions

Content added Content deleted
No edit summary
Line 8: Line 8:
List any pragmatic directives supported by the language,   and demonstrate how to activate and deactivate the pragmatic directives and to describe or demonstrate the scope of effect that the pragmatic directives have within a program.
List any pragmatic directives supported by the language,   and demonstrate how to activate and deactivate the pragmatic directives and to describe or demonstrate the scope of effect that the pragmatic directives have within a program.
<br><br>
<br><br>
=={{header|6502 Assembly}}==
These are common to most assemblers but syntax may vary. Place them in your source code file. As with code, all of these can be deactivated by commenting them out.

* <code>org $XXXX</code>: Tells the assembler which memory address to begin assembling at. The instruction after this directive will begin at that address, and then code will be placed sequentially until the end of file or the next ORG directive is reached.
* <code>equ</code>: Equates a label to a specific numeric value. Each instance of that label in your code becomes a constant if preceded by a # and a memory address otherwise.
* <code>include "filename"</code>: Adds an additional file to your source code. The assembler treats the contents as 6502 instructions when assembling. For most assemblers the location of the <code>include</code> statement matters, since it is treated as if the contents were copy-pasted inline.
* <code>incbin "filename"</code>: Adds a binary file to your source code. For most assemblers the location of the <code>incbin</code> statement matters, since it is treated as if the contents were copy-pasted inline.
* <code>ifdef</code>/<code>ifndef</code>/<code>else</code>/<code>endif</code>: The assembler will skip anything inside an IFDEF block if the designated label wasn't defined. IFNDEF and ELSE are the opposite. To make an IFDEF statement true, you only need to have that label defined in your source. (The value doesn't matter as long as it appears.) Here's an example:

<lang 6502asm>NMOS_6502 equ 1
ifdef NMOS_6502
txa
pha
else
phx ;NMOS_6502 doesn't have this instruction.
endif ; every ifdef/ifndef needs an endif</lang>

* <code>db</code>/<code>dw</code>/<code>byte</code>/<code>word</code>: Defines a data block. The assembler treats these values as arbitrary bytes rather than machine instructions. Used for tables of values, etc.

* <code>align #</code> Fills in the next # bytes with padding (typically zero, but this value can be adjusted in your assembler's settings. Useful for preventing wasted cycles that occur when crossing a page boundary.

* <code>macro</code>: Defines a macro. Any time the macro name appears in your source document, the assembler replaces it with the definition. Any parameters supplied to the macro are also plugged in. This is useful for parameter passing which would otherwise be very tedious. Every macro must end with an <code>endm</code>.



=={{header|Ada}}==
=={{header|Ada}}==