mirror of
https://github.com/michaelcmartin/Ophis.git
synced 2024-11-18 11:06:07 +00:00
623 lines
12 KiB
HTML
623 lines
12 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>Assembler directives</TITLE
|
|
><META
|
|
NAME="GENERATOR"
|
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
|
|
REL="HOME"
|
|
TITLE="Programming with Ophis"
|
|
HREF="book1.html"><LINK
|
|
REL="UP"
|
|
TITLE="Ophis Command Reference"
|
|
HREF="a1167.html"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="Macros"
|
|
HREF="x1354.html"></HEAD
|
|
><BODY
|
|
CLASS="SECTION"
|
|
BGCOLOR="#FFFFFF"
|
|
TEXT="#000000"
|
|
LINK="#0000FF"
|
|
VLINK="#840084"
|
|
ALINK="#0000FF"
|
|
><DIV
|
|
CLASS="NAVHEADER"
|
|
><TABLE
|
|
SUMMARY="Header navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TH
|
|
COLSPAN="3"
|
|
ALIGN="center"
|
|
>Programming with Ophis</TH
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="left"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="x1354.html"
|
|
ACCESSKEY="P"
|
|
><<< Previous</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
>Ophis Command Reference</TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
> </TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="SECTION"
|
|
><H1
|
|
CLASS="SECTION"
|
|
><A
|
|
NAME="AEN1394"
|
|
>Assembler directives</A
|
|
></H1
|
|
><P
|
|
> Assembler directives are all instructions to the assembler
|
|
that are not actual instructions. Ophis's set of directives
|
|
follow.
|
|
</P
|
|
><P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.outfile</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>filename</I
|
|
>:
|
|
Sets the filename for the output binary if one has not
|
|
already been set. If no name is ever set, the output will
|
|
be written to <TT
|
|
CLASS="LITERAL"
|
|
>ophis.bin</TT
|
|
>.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.advance</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>address</I
|
|
>
|
|
[, <I
|
|
CLASS="EMPHASIS"
|
|
>filler</I
|
|
>]: Forces the program
|
|
counter to be <I
|
|
CLASS="EMPHASIS"
|
|
>address</I
|
|
>. Unlike
|
|
the <TT
|
|
CLASS="LITERAL"
|
|
>.org</TT
|
|
>
|
|
directive, <TT
|
|
CLASS="LITERAL"
|
|
>.advance</TT
|
|
> outputs bytes (the
|
|
value of <I
|
|
CLASS="EMPHASIS"
|
|
>filler</I
|
|
>, or zeroes if it is
|
|
unspecified) until the program counter reaches a
|
|
specified address. Attempting
|
|
to <TT
|
|
CLASS="LITERAL"
|
|
>.advance</TT
|
|
> to a point behind the
|
|
current program counter is an assemble-time error.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.alias</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>label</I
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>value</I
|
|
>:
|
|
The .alias directive assigns an arbitrary value to a
|
|
label. This value may be an arbitrary argument, but
|
|
cannot reference any label that has not already been
|
|
defined (this prevents recursive label
|
|
dependencies).
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.byte</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>arg</I
|
|
> [
|
|
, <I
|
|
CLASS="EMPHASIS"
|
|
>arg</I
|
|
>, ... ]: Specifies a series of
|
|
arguments, which are evaluated, and strings, which are
|
|
included as raw ASCII data. The final results of these
|
|
arguments must be one byte in size. Seperate constants
|
|
are seperated by comments.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.cbmfloat</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>string</I
|
|
>
|
|
[ , <I
|
|
CLASS="EMPHASIS"
|
|
>string</I
|
|
>, ... ]: Specifies a
|
|
series of strings, which are interpreted as floating
|
|
point constants, and then included in the 5-byte floating
|
|
point format used by the Commodore BASICs. This format is
|
|
8 bits of exponent, followed by a sign bit and a 31-bit
|
|
big-endian mantissa fraction. (The 1 in front of the
|
|
binary point is presumed to be present.) An exponent of 0
|
|
specifies a constant of 0, and the exponent is shifted up
|
|
by 129 before being stored.
|
|
</P
|
|
><P
|
|
> Because IEEE-754 doesn't perfectly match the Commodore's
|
|
system, if you wish to precisely replicate individual
|
|
constants that cannot be represented exactly you may have
|
|
better luck with the following program, which will run on
|
|
both the Commodore 64 and VIC-20:
|
|
</P
|
|
><TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="90%"
|
|
><TR
|
|
><TD
|
|
><PRE
|
|
CLASS="PROGRAMLISTING"
|
|
>10 CLR:V=0:PV=PEEK(45)+256*PEEK(46)+2
|
|
20 INPUT "NUMBER (0 TO QUIT)";V
|
|
30 IF V=0 THEN END
|
|
40 PRINT ".BYTE";
|
|
50 FOR I=0 TO 4
|
|
60 IF I>0 THEN PRINT CHR$(157);",";
|
|
70 PRINT PEEK(PV+I);:NEXT I:PRINT:GOTO 20</PRE
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><P
|
|
>This program will print out
|
|
a <TT
|
|
CLASS="LITERAL"
|
|
>.byte</TT
|
|
> directive for you to include in
|
|
your program to represent that number.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.checkpc</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>address</I
|
|
>:
|
|
Ensures that the program counter is less than or equal to
|
|
the address specified, and emits an assemble-time error
|
|
if it is not. <I
|
|
CLASS="EMPHASIS"
|
|
>This produces no code in the
|
|
final binary - it is there to ensure that linking a large
|
|
amount of data together does not overstep memory
|
|
boundaries.</I
|
|
>
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.data</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>[label]</I
|
|
>:
|
|
Sets the segment to the segment name specified and
|
|
disallows output. If no label is given, switches to the
|
|
default data segment.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.incbin</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>filename</I
|
|
>
|
|
[, <I
|
|
CLASS="EMPHASIS"
|
|
>offset</I
|
|
>
|
|
[, <I
|
|
CLASS="EMPHASIS"
|
|
>length</I
|
|
>]]: Inserts the contents of
|
|
the file specified as binary data. Use it to include
|
|
graphics information, precompiled code, or other
|
|
non-assembler data. You may also optionally specify an
|
|
index to start including from, or a length to only
|
|
include a subset.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.include</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>filename</I
|
|
>:
|
|
Includes the entirety of the file specified at that point
|
|
in the program. Use this to order your final sources, if
|
|
you aren't doing it via the command line.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.org</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>address</I
|
|
>:
|
|
Sets the program counter to the address
|
|
specified. <I
|
|
CLASS="EMPHASIS"
|
|
>This does not emit any code in and
|
|
of itself, nor does it overwrite anything that previously
|
|
existed.</I
|
|
> If you wish to jump ahead in memory,
|
|
use <TT
|
|
CLASS="LITERAL"
|
|
>.advance</TT
|
|
>.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.require</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>filename</I
|
|
>:
|
|
Includes the entirety of the file specified at that point
|
|
in the program. Unlike <TT
|
|
CLASS="LITERAL"
|
|
>.include</TT
|
|
>,
|
|
however, code included with <TT
|
|
CLASS="LITERAL"
|
|
>.require</TT
|
|
>
|
|
will only be inserted once.
|
|
The <TT
|
|
CLASS="LITERAL"
|
|
>.require</TT
|
|
> directive is useful for
|
|
ensuring that certain code libraries are somewhere in the
|
|
final binary. They are also very useful for guaranteeing
|
|
that macro libraries are available.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.space</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>label</I
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>size</I
|
|
>:
|
|
This directive is used to organize global variables. It
|
|
defines the label specified to be at the current location
|
|
of the program counter, and then advances the program
|
|
counter <I
|
|
CLASS="EMPHASIS"
|
|
>size</I
|
|
> steps ahead. No actual
|
|
code is produced. This is equivalent to <TT
|
|
CLASS="LITERAL"
|
|
>label:
|
|
.org ^+size</TT
|
|
>.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.text</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>[label]</I
|
|
>:
|
|
Sets the segment to the segment name specified and allows
|
|
output. If no label is given, switches to the default
|
|
text segment.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.word</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>arg</I
|
|
> [
|
|
, <I
|
|
CLASS="EMPHASIS"
|
|
>arg</I
|
|
>, ... ]:
|
|
Like <TT
|
|
CLASS="LITERAL"
|
|
>.byte</TT
|
|
>, but values are all treated
|
|
as two-byte values and stored low-end first (as is the
|
|
6502's wont). Use this to create jump tables (an
|
|
unadorned label will evaluate to that label's location)
|
|
or otherwise store 16-bit data.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.dword</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>arg</I
|
|
> [
|
|
, <I
|
|
CLASS="EMPHASIS"
|
|
>arg</I
|
|
>, ...]:
|
|
Like <TT
|
|
CLASS="LITERAL"
|
|
>.word</TT
|
|
>, but for 32-bit
|
|
values.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.wordbe</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>arg</I
|
|
> [
|
|
, <I
|
|
CLASS="EMPHASIS"
|
|
>arg</I
|
|
>, ...]:
|
|
Like <TT
|
|
CLASS="LITERAL"
|
|
>.word</TT
|
|
>, but stores the value in a
|
|
big-endian format (high byte first).
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.dwordbe</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>arg</I
|
|
> [
|
|
, <I
|
|
CLASS="EMPHASIS"
|
|
>arg</I
|
|
>, ...]:
|
|
Like <TT
|
|
CLASS="LITERAL"
|
|
>.dword</TT
|
|
>, but stores the value high
|
|
byte first.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.scope</TT
|
|
>: Starts a new scope
|
|
block. Labels that begin with an underscore are only
|
|
reachable from within their innermost
|
|
enclosing <TT
|
|
CLASS="LITERAL"
|
|
>.scope</TT
|
|
>
|
|
statement.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.scend</TT
|
|
>: Ends a scope block. Makes the
|
|
temporary labels defined since the
|
|
last <TT
|
|
CLASS="LITERAL"
|
|
>.scope</TT
|
|
> statement unreachable, and
|
|
permits them to be redefined in a new
|
|
scope.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.macro</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>name</I
|
|
>:
|
|
Begins a macro definition block. This is a scope block
|
|
that can be inlined at arbitrary points
|
|
with <TT
|
|
CLASS="LITERAL"
|
|
>.invoke</TT
|
|
>. Arguments to the macro
|
|
will be bound to temporary labels with names like
|
|
<TT
|
|
CLASS="LITERAL"
|
|
>_1</TT
|
|
>, <TT
|
|
CLASS="LITERAL"
|
|
>_2</TT
|
|
>, etc.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.macend</TT
|
|
>: Ends a macro definition block.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> <TT
|
|
CLASS="LITERAL"
|
|
>.invoke</TT
|
|
> <I
|
|
CLASS="EMPHASIS"
|
|
>label</I
|
|
> [<I
|
|
CLASS="EMPHASIS"
|
|
>argument</I
|
|
> [,
|
|
<I
|
|
CLASS="EMPHASIS"
|
|
>argument</I
|
|
> ...]]: invokes (inlines) the
|
|
specified macro, binding the values of the arguments to the
|
|
ones the macro definition intends to read. A shorthand
|
|
for <TT
|
|
CLASS="LITERAL"
|
|
>.invoke</TT
|
|
> is the name of the macro to
|
|
invoke, backquoted.
|
|
</P
|
|
></LI
|
|
></UL
|
|
></DIV
|
|
><DIV
|
|
CLASS="NAVFOOTER"
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"><TABLE
|
|
SUMMARY="Footer navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="x1354.html"
|
|
ACCESSKEY="P"
|
|
><<< Previous</A
|
|
></TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="book1.html"
|
|
ACCESSKEY="H"
|
|
>Home</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
> </TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>Macros</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="a1167.html"
|
|
ACCESSKEY="U"
|
|
>Up</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
> </TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |