FLEX Assembler: Technical Systems Consultants, Inc
FLEX Assembler: Technical Systems Consultants, Inc
FLEX Assembler: Technical Systems Consultants, Inc
Page
I. Introduction 1
V. Standard Directives 25
VII. Macros 37
I . INTRODUCTION
The 6809 Mnemonic Assembler is a fast and powerful disk based assembler
interfaced to the FLEXt disk operating system. It accepts all standard
Motorola mnemonics for the 6809 instruction set as well as all standard
6800 and 6801 mnemonics. Macros and conditional assembly are supported
as well as numerous other directives for convenient assembler control.
The assembler executes in two passes and can accept any size file on the
disk so long as sufficient memory is installed to contain the symbol
table. Output is in the form of a binary disk file or a hexadecimal tape
as well as an assembled listing output which may be routed to a printer
or to a disk file through the facilities of FLEX.
- 1 -
TSC 6809 Assembler
The disk version of the 6809 Mnemonic Asssembler is very simple to use.
There are no built-in editing functions - you must have a previously
edited source file on disk before using the assembler. This file must
be a standard FLEX text file which is simply textual lines terminated by
a carriage return. There should be no line numbers or control
characters (except for the carriage returns) in the file. When you have
both the assembler and the edited source file on a disk or disks which
are inserted in a powered up system, you are ready to begin.
+++ASMB,<filename>
The three plus signs are FLEX’s ready prompt, ASMB is the name of the
assembler file (it has a .CMD extension), and the <filename> is the
standard FLEX specification for the source file you wish to assemble.
The <filename> defaults to a .TXT extension and to the assigned working
drive if an explicit extension and drive number are not given. In this
and forthcoming example command lines, a comma is used to separate
items. It is also possible to use a space or spaces in this capacity.
The object code can be in the form of a binary disk file, a hex output
to tape, or no object code output at all. Since no specifications are
made concerning object code output in the above example, the assembler
will assume the default case which is a binary disk file. Since no name
was specified, the output binary file will assume the same name as the
input source file specified but with a .BIN extension. If such a file
already exists, you will be asked:
- 2 -
TSC 6809 Assembler
to which you may respond ’Y’ which will delete the existing file and
continue to create the new file or ’N’ which will immediately terminate
the assembly, returning to FLEX with the old binary file remaining
intact.
Now we shall go one step further and add a set of single character
option flags which may be set on the command line as follows:
The square brackets indicate that the binary file spec and the option
list are optional. The plus sign is required to separate the option
list from the file specifications. The <option list> is a set of single
character flags which either enable or disable a particular option. In
all cases they reverse the sense of the particular option from its
default sense. There may be any number of options specified and they
may be specified in any order. There may not be spaces within the
option list. Following is a list of the available options and what they
represent:
- 3 -
TSC 6809 Assembler
The assembler has a facility for passing information from the command
line directly into the source program. A maximum of three pieces of
information or "command line parameters" may be passed to the program.
These parameter are simply strings of characters that will be
substituted into the source listing as it is read in by the assembler.
These parameters are expressed in the command line in the manner shown
here:
The parameters are optional but must be separated from the rest of the
line by the second plus sign and from each other by commas. As stated,
these parameters are simply strings of characters. They may be supplied
in two ways: as a string of characters enclosed by a delimiter or just a
string of characters with no spaces or commas embedded. The
"delimiters" which can be used to enclose a string are the single quote
(’) and the double quote ("). Either can be used but for a particular
string the beginning delimiter and the ending delimiter must be the
same. The reason for using a delimited string is to pass in a string
with commas and/or spaces which cannot be in an un-delimited string.
Note that if one wishes to enter a command line parameter but no
options, he must still place both plus signs in the command as seen in
this example command line:
+++ASMB,ANYFILE,++PARAMETER1,PARAMETER2
The assembler does not have a built in means for outputting the
assembled listing to a hardcopy device. This operation is, however,
available through the facilities of FLEX. To do so one must use the ’P’
command provided with FLEX. This ’P’ command reads a printer driver
file which you can supply to output to any hardcopy device you want. It
effectively switches the output of the assembler from going to the
terminal to going to the printer. For example:
+++P,ASMB,TESTFILE
- 5 -
TSC 6809 Assembler
EXAMPLES:
ASMB,TEST
Assembles a file called TEST-TXT on the assigned working drive
and creates a binary file called TEST.BIN on the same drive.
The assembled listing is output to the terminal as is the
symbol table.
ASMB,TEST,+LS
Same as before except that no listing is output (except for
any lines with errors) and no symbol table is output.
ASMB,0.TEST,1.TEST.CMD,+LSY
Assembles a file from drive 0 called TEST.TXT and produces a
binary file on drive 1 called TEST.CMD. No listing or symbol
table is output and if a file by the name of TEST.CMD already
resides on drive 1, it will be automatically deleted before
the assembly starts.
l.ASMB,0.TEST.BAK,+BNGS
Loads the assembler itself from drive 1 and assembles a file
called TEST.BAK found on drive 0. No binary file is produced.
The assembled listing is output with line numbers turned on
and multiple line generated code turned off. No symbol table
is printed.
ASMB,0.TEST.BAK,+GSBNP26
This command performs just like the last with two exceptions.
First, the assembler itself is loaded from the whatever the
assigned system drive is. Second, the assembled listing
output does not begin until the assembler reaches page number
26.
- 6 -
TSC 6809 Assembler
- 7 -
TSC 6809 Assembler
The four fields are described here along with their format
specifications. The fields are free format which means there may be any
number of spaces separating each field. In general, no spaces are
allowed within a field.
This field may contain a symbolic label or name which is assigned the
instruction’s address and may be called upon throughout the source
program.
1) The label must begin in column one and must be unique. Labels
are optional. If the label is to be omitted, the first
character of the line must be a space.
2) A label may consist of letters (A-Z or a-z), numbers (0-9), or
an underscore (_ or 5F hex). Note that upper and lower case
letters are not considered equivalent. Thus ’ABC’ is a
different label from ’Abc’.
3) Every label must begin with a letter.
4) Labels may be of any length, but only the first 6 characters
are significant.
5) The label field must be terminated by a space or a return.
OPCODE FIELD:
OPERAND FIELD:
- 8 -
TSC 6809 Assembler
COMMENT FIELD:
The comment field may be used to insert comments on each line of source.
Comments are for the programmer’s convenience only and are ignored by
the assembler.
1) The comment field is always optional.
2) This field must be preceded by a space.
3) Comments may contain any characters from SPACE (hex 20) thru
DELETE (hex 7F).
4) This field is terminated by a carriage return.
REGISTER SPECIFICATION
Many opcodes require that the operand following them specify one or more
registers. EXG and TFR require two registers specified, push and pull
allow any number, and the indexed addressing mode requires specification
of the register by which indexing is to be done. The following are
possible register names:
A,B,CC,DP,X,Y,U,S,D,PC
The EXG and TFR instructions require two register specs separated by a
comma. The push and pull instructions allow any number of registers to
be specified, again, separated by commas. Indexed addressing requires
one of X,Y,U, or S as explained under the indexed addressing mode
description.
EXPRESSIONS
Many opcodes require that the operand supply further data or information
in the form of an expression. This expression may be one or more items
combined by any of four operator types: arithmetic, logical, relational,
and shift.
- 9 -
TSC 6809 Assembler
ITEM TYPES:
- 10 -
TSC 6809 Assembler
EXPRESSION OPERATORS
a) ARITHMETIC OPERATORS
The arithmetic operators are as follows:
Operator Meaning
b) LOGICAL OPERATORS
The logical operators are as follows:
Operator Meaning
c) RELATIONAL OPERATORS
The relational operators are as follows:
Operator Meaning
= Equal
< Less than
> Greater than
<> Not equal
<= Less than or equal
>= Greater than or equal
OPERATOR PRECEDENCE
1) Parenthesized expressions
2) Unary + and -
3) Shift operators
4) Multiply and Divide
5) Binary Addition and Subtraction
6) Relational Operators
7) Logical NOT Operator
8) Logical AND and OR Operators
- 12 -
TSC 6809 Assembler
PROGRAMMING MODEL
There are several possible addressing modes in the 6809 instruction set.
One of the best features of the 6809 is the consistency or regularity
built into the instruction set. For the most part, any instruction
which addresses memory can use any of the addressing modes available.
It is not necessary to remember which instructions can use which
addressing modes, etc. The addressing modes and a brief description of
each follow.
1) Inherent
Inherent addressing refers to those instructions which have no
addressing associated with them.
Example: ABX add B accumulator to X
- 13 -
TSC 6809 Assembler
2) Accumulator
Accumulator addressing is done in those instructions which can
specify the A or B accumulator. In some cases this may be the
16-bit D accumulator.
Example: DECA decrement the A accumulator
3) Immediate
In Immediate addressing the byte or bytes following the opcode are
the information being addressed. These byte or bytes are specified
as part of the instruction.
Example: LDA #8 load immediate value (8) into A
5) Extended
In Extended addressing, the two bytes (16-bits) following the opcode
are used as an absolute memory address value.
Example: LDA $1000 load A from memory location 1000 hex
6) Direct
In Direct addressing, the single byte (8-bits) following the opcode
is used as a pointer into a 256-byte window or "page" of memory.
The page used for this purpose is the one currently found in the
Direct Page register. Thus, the effective address is a
concatenation of the Direct Page register as the most significant
half and the byte following the opcode as the least significant
half.
Example: LDA $22 load A from memory location $XX22 where XX
represents the contents of the DP register
7) Extended Indirect
In Extended Indirect addressing, the 16-bit value following the
opcode is used to point to two bytes in memory which are used as the
effective address.
Example: LDA [$A012] loads A from the address stored at
locations $A012 and $A013
- 14 -
TSC 6809 Assembler
8) Indexed
The Indexed addressing mode of the 6809 is an extremely powerful
method of specifying addresses which is, in general, some sort of
offset from the value stored in one of the registers X, Y, U, S, or
PC. There are several forms of indexed addressing which could each
be considered an addressing mode in itself. We will, however,
discuss each as a subset of Indexed addressing in general. Note
that except for the Auto-increment and Auto-decrement modes,
determining the effective address has no effect on the register
being used as the index.
8c) Auto-Increment
The contents of the selected register are used as the effective
address with no offset permitted. After that effective address has
been determined, the selected register is incremented by one (for
single plus sign) or two (double plus sign).
Example: LDA 0,X+ loads A from X then bumps X by 1
LDD ,Y++ loads D from Y then bumps Y by 2
8d) Auto-Decrement
In auto-decrementing, the selected register is first decremented by
one (single minus sign) or two (double minus sign). The resulting
value, with no offset, is used as the effective address.
Example: LDA 0,-U decrements U by 1 then loads A from address in U
LDU ,--S decrements S by 2 then loads U from address in S
- 15 -
TSC 6809 Assembler
All the Indexed Addressing modes above can also be used in an indirect
fashion by enclosing the operand in square brackets. When this is done,
the effective address as described in all the above modes is no longer
the final effective address. Instead, the two bytes pointed to by that
address are used as the effective address.
PC Relative Addressing
- 16 -
TSC 6809 Assembler
The 6809 assembler has a mechanism for forcing the assembler to perform
either direct or extended addressing. Under normal conditions, the
assembler will use direct addressing when possible. To force the
assembler to use extended addressing no matter what the conditions,
simply precede the operand with a greater than sign (’>’). For example,
suppose the DP register was set to $00 (this is the default on reset of
the cpu), and that we have a label, BUFPNT, which is at memory location
$0010. Normally the instruction:
LDX BUFPNT
LDX >BUFPNT
LDX <BUFPNT
would force direct addressing. Note that in both cases the greater than
or less than sign must be the first character in the operand.
- 17 -
TSC 6809 Assembler
- 18 -
TSC 6809 Assembler
- 19 -
TSC 6809 Assembler
CLR Clear
SOURCE FORM: CLRA; CLRB; CLR (Q)
6800 ALTERNATES: CLR A; CLR B
CMP Compare
SOURCE FORM: CMPA (P); CMPB (P); CMPD (P); CMPX (P);
CMPY (P); CMPU (P); CMPS (P)
6800 ALTERNATES: CMP A (P); CMP B (P); CPX (P)
DEC Decrement
SOURCE FORM: DECA, DECB, DEC (Q)
6800 ALTERNATES: DEC A; DEC B
INC Increment
SOURCE FORM: INCA, INCB, INC (Q)
6800 ALTERNATES: INC A; INC B
- 20 -
TSC 6809 Assembler
NOP No operation
SOURCE FORM: NOP
- 21 -
TSC 6809 Assembler
TST Test
SOURCE FORM: TSTA; TSTB; TST (Q)
6800 ALTERNATES: TST A; TST B
- 22 -
TSC 6809 Assembler
ABA Add B to A
CBA Compare B to A
DEX Decrement X
INX Increment X
TAB Transfer A to B
TAP Transfer A to CC
TBA Transfer B to A
TPA Transfer CC to A
TSX Transfer S to X
TXS Transfer X to S
- 23 -
TSC 6809 Assembler
CONVENIENCE MNEMONICS
- 24 -
TSC 6809 Assembler
ORG SETDP
END PAG
RMB SPC
FCB NAM or TTL
FDB STTL
FCC ERR
EQU RPT
SET LIB
REG OPT
ORG
The ORG statement is used to set a new code ’Origin’. This simply means
that a new address is set into the location Counter (or program counter)
so that subsequent code will be placed at the new location. The form is
as follows:
ORG <expression>
END
The END pseudo-op is used to signal the assembler that the end of the
source input has occurred. This terminates whatever pass is currently
being executed. No label is allowed and no code is generated. An
expression may be given (as shown below) as the transfer address to be
placed in a binary file. It is optional, and if supplied when no binary
file is being produced, will be ignored.
END [<expression>]
Note that an end statement is not strictly required, but is the only
means of getting a transfer address appended to a binary output file.
- 25 -
TSC 6809 Assembler
RMB
FCB
The FCB or Form Constant Byte directive is used to set associated memory
bytes to some value as determined by the operand. FCB may be used to
set any number of bytes as shown below:
Where <expr. x> stands for some expression. Each expression given
(separated by commas) is evaluated to 8 bits and the resulting
quantities are stored in successive memory locations. The label is
optional.
FDB
The FDB or Form Double Byte directive is used to setup 16 bit quantities
in memory. It is exactly like the FCB directive except that 16 bit
quantities are evaluated and stored in memory for each expression given.
The form of the statement is:
FCC
- 26 -
TSC 6809 Assembler
Note that more than one delimited string may be placed on a line as in
the second example.
EQU
SET
- 27 -
TSC 6809 Assembler
REG
The REG directive allows the user to setup a list of registers for use
by the push and pull instructions. This list is represented by a value
and the value is equated to the label supplied. In this respect, the
REG directive is similar to the EQU directive. The correct form of the
REG directive is:
PSHS A,B,Y,U,DP
PULS A,B,Y,U,DP
To make things more convenient and less error prone the REG directive
could be used as shown here:
Now all the pushes and pulls referred to above could be accomplished
with the statements:
PSHS #RLIST2
PULS #RLIST2
Of course, the register list may still be typed out on push and pull
instructions or an immediate value (with the desired bit pattern) may be
specified.
SETDP
The SETDP or Set Direct Page directive allows the user to set which
memory page the assembler will use for the direct page addressing mode.
The correct format is as follows:
- 28 -
TSC 6809 Assembler
PAG
The PAG directive causes a page eject in the output listing and prints a
header at the top of the new page. Note that the ’PAG’ option must have
been previously selected in order for this directive to take effect. It
is possible to assign a new number to the new page by specifying such in
the operand field. If no page number is specified, the next consecutive
number will be used. No label is allowed and no code is produced. The
PAG operator itself will not appear in the listing unless some sort of
error is encountered. The proper form is:
PAG [<expression>]
Where the expression is optional. The first page of a listing does not
have the header printed on it and is considered to be page 0. The
intention here is that all options, title, and subtitle may be setup and
followed by a PAG directive to start the assembled listing at the top of
page 1 without the option, title, or subtitle instructions being in the
way.
SPC
The SPC or Space directive causes the specified number of spaces (line
feeds) to be inserted into the output listing. The general form is:
The space count can be any number from 0 to 255. If the page option is
selected, SPC will not cause spacing past the top of a new page. The
<keep count> is optional and is the number of lines which the user
wishes to keep together on a page. If there are not enough lines left
on the current page, a page eject is performed. If there are <keep
count> lines left on the page (after printing <space count> spaces),
output will continue on the current page. If the page option is not
selected, the <keep count> will be ignored. If no operand is given
(ie. just the directive SPC), the assembler will default to one blank
line in the output listing.
TTL OR NAM
The TTL or NAM directive allows the user to specify a title or name to
the program being assembled.. This title is then printed in the header
at the top of each output listing page if the page option is selected.
If the page option is not selected, this directive is ignored. The
proper form is:
All the text following the TTL or NAM directive (excluding leading
spaces) is placed in the title buffer. Up to 32 characters are allowed
with any excess being ignored. It is possible to have any number of TTL
- 29 -
TSC 6809 Assembler
STTL
ERR
All text past the ERR directive (excluding leading spaces) is printed as
an error message (it will be preceded by three asterisks) in the output
listing. Note that the ERR directive line itself is not printed. A
common use for the ERR directive is in conjunction with conditional
assembly such that some user-defined illegal condition may be reported
as an error.
RPT
RPT <count>
where <count> may be any number from 1 to 127. For example, the
following two lines:
RPT 4
ASLB
- 30 -
TSC 6809 Assembler
ASLB
ASLB
ASLB
ASLB
Some directives, such as IF or MACRO, may not be repeated with the RPT
command. These cases are where it is illogical or impractical to do so.
If attempted, the RPT will simply be ignored.
LIB
The LIB or Library directive allows the user to specify an external file
for inclusion in the assembled source output. Under normal conditions,
the assembler reads all input from the file specified on the calling
line. The LIB directive allows the user to temporarily obtain the source
lines from some other file. When all the lines in that external file
have been read and assembled, the assembler resumes reading of the
original source file. The proper syntax is:
OPT
The OPT or Option directive allows the user to choose from several
different assembly options which are available to him. These options
are generally related to the format of the output listing and object
code. The options which may be set with this command are listed below.
There are several options not listed here which may be set from the FLEX
command line. See the appropriate section earlier in the manual for
these options. The proper form of this instruction is:
Note that any number of options may be given on one line if separated by
commas. No label is allowed and no spaces may be imbedded in the option
list. The options are all set during pass one only although the
instruction is parsed in pass two as well for error reporting purposes.
If contradicting options are specified, the last one appearing takes
precedence. If a particular option is not specified, the default case
for that option takes effect. The default cases are signified below by
an asterisk.
- 31 -
TSC 6809 Assembler
- 32 -
TSC 6809 Assembler
IF <expression>
.
. conditional code goes here
.
ENDIF
- 33 -
TSC 6809 Assembler
IF <expression>
.
. this code assembled if expression is true
.
ELSE
.
. this code assembled if expression is false
.
ENDIF
The ELSE statement does not require an operand and there may be only one
ELSE between an IF-ENDIF pair.
IFN <expression>
.
. this code assembled if expression is FALSE
.
ELSE
.
. this code assembled if expression is TRUE
.
ENDIF
- 34 -
TSC 6809 Assembler
As can be seen, the two strings are separated by a comma. There are two
types of strings, one enclosed by delimiters the other not. The
delimited type may use either a single quote (’) or double quote (") as
the delimiter. This type of string is made up of all the characters
after the first delimiter until the second delimiter is found. The
second type of string is simply a group of characters, starting with a
non-space and containing no spaces or commas. Thus if you need spaces
or commas in a string, you must use the delimited type of string. It is
possible to specify a null string by placing two delimiters in a row or
by simply leaving the string out completely. Note that there may be no
spaces after string 1 and before the separating comma nor after the
comma and before string 2. As with IFN, the IFNC directive simply
reverses the sense of the test such that code immediately following an
IFNC directive would be assembled if the strings did NOT compare.
The IF-skip type of conditional assembly is a method which does not use
(in fact does not allow) a related ENDIF or ELSE. Instead, the
assembler is caused to skip a specified number of lines of source
depending on the result of the expression or string comparison.
IMPORTANT NOTE:
This type of conditional assembly is
ONLY allowed within the body of a macro.
Any use of it outside a macro will
result in an error. Macros are defined
in the next section.
As before, the possible directives are: IF, IFN, IFC, and IFNC. This
type of conditional assembly is performed with a single instruction.
Instead of code being assembled on a true result, the specified number
of lines are SKIPPED. This number of lines can be in a forward or
reverse direction. The syntax is as shown:
IF <expression>,<skip count>
or
IFC <string 1>,<string 2>,<skip count>
The skip count must be a decimal number between 1 and 255. It may be
preceded by a plus or minus sign. A positive number produces a forward
skip while a negative number produces a backwards skip. A skip count of
zero has no effect (the instruction following the IF directive will be
executed next). A skip count of one will cause the second line after
the IF statement to be the next one executed (the one line directly
following the IF statement is ignored). A skip count of negative one
will cause the line just before the skip count to be the next one
executed. The assembler will not skip past the end or beginning of the
macro which contains the IF-skip statement. If a skip count is
specified which is beyond these limits, the assembler will be left
- 35 -
TSC 6809 Assembler
IMPORTANT NOTE
- 36 -
TSC 6809 Assembler
VII. MACROS
The first step is to define the macro. This must be done BEFORE THE
FIRST CALL to the macro. It is good practice to define all macros early
in a program. The definition is initiated with a MACRO directive and
terminated by an ENDM directive. The definition of our example would be
as follows:
ASLD4 MACRO
ASLB
ROLA
ASLB
ROLA
ASLB
ROLA
ASLB
ROLA
ENDM
The first line is the MACRO directive. Note that the name of the macro
is specified with this directive by placing it in the label field. This
macro name should follow all the rules for labels. It will NOT be
placed in the symbol table, but rather in a macro name table. The body
of the macro follows and is simply lines of standard assembly source
which shift the ’D’ register left four places. The definition is
terminated by the ENDM directive.
- 37 -
TSC 6809 Assembler
At this point we may continue with our assembly program and when we
desire to have the ’D’ register shifted left four places, simply call
the macro as follows:
.
.
LDA VALUE
LDB VALUE+1
ASLD4 here is the macro call
STD RESULT
.
.
You can see that calling a macro consists of simply placing its name in
the mnemonic field of a source line. When the assembler sees the above
call, it realizes that the instruction is not a standard 6809 mnemonic,
but rather a macro that has been previously defined. The assembler will
then replace the ASLD4 with the lines which make up the body of that
macro or "expand" the macro. The result would be the following
assembled code:
.
.
LDA VALUE
LDB VALUE+1
ASLB the body of the macro
ROLA replaces the call
ASLB
ROLA
ASLB
ROLA
ASLB
ROLA
STD RESULT
.
.
You should note that a macro call differs from a subroutine call in that
the macro call results in lines of code being placed in-line in the
program where a subroutine call results in the execution of the routine
at run-time. Five calls to a subroutine still only requires one copy of
the subroutine while five calls to a macro results in five copies of the
macro body being inserted into the program.
- 38 -
TSC 6809 Assembler
PARAMETER SUBSTITUTION
If macros were limited to what was described above, they would probably
not be worth the space it took to implement them in the assembler. The
real power of macros comes in "parameter substitution". By that we mean
the ability to pass parameters into the macro body from the calling
line. In this manner, each expansion of a macro can be different.
ADD3 MACRO
LDD LOC1 get first value in ’D’
ADDD LOC2 add in second value
ADDD LOC3 add in third value
STD RESULT store result
ENDM
Now let’s assume we need to add three numbers like this in several
places in the program, but the locations from which the numbers come and
are to be stored are different. We need a method of passing these
locations into the macro each time it is called and expanded. That is
the function of parameter substitution. The assembler lets you place up
to nine parameters on the calling line which can be substituted into the
expanded macro. The proper form for this is:
MACNAM <prm.l>,<prm.2>,<prm.3>,...,<prm.9>
where "MACNAM" is the name of the macro being called. Each parameter
may be one of two types: a string of characters enclosed by like
delimiters and a string of characters not enclosed by delimiters which
contains no embedded spaces or commas. The delimiter for the first type
may be either a single quote (’) or a double quote (") but the starting
and ending delimiter of a particular string must be the same. A comma
is used to separate the parameters. These parameters are now passed
into the macro expansion by substituting them for 2-character "dummy
parameters" which have been placed in the macro body on definition.
These 2-character dummy parameters are made up of an ampersand (&)
followed by a single digit representing the number of the parameter on
the calling line as seen above. Thus any occurence of the dummy
parameter, "&1", would be replaced by the first parameter found on the
calling line.
Let’s re-do our ADD3 macro to demonstrate this process. The definition
of ADD3 now looks like this:
ADD3 MACRO
LDD &l get first value in ’D’
ADDD &2 add in second value
ADDD &3 add in third value
STD &4 store result
ENDM
- 39 -
TSC 6809 Assembler
ADD3 LOC1,LOC2,LOC3,RESULT
When this macro was expanded, the &l would be replaced with LOC1, the &2
would be replaced with LOC2, etc. The resulting assembled code would
appear as follows:
ADD3 ACE,TWO,LOC3,LOC1
MASK&4
- 40 -
TSC 6809 Assembler
MASK\&4
When the assembler expands the macro containing this expression, it will
recognize the backslash, remove it, and leave the ampersand and
following number intact.
Another case where this can be useful is when a macro is defined within
a macro (that is possible!) and you wish to place dummy parameters in
the inner macro.
To portray the use of EXITM, assume we have some macro called XYZ which
has two parts. The first part should always be expanded, but the second
should only be expanded in certain cases. We could use EXITM and the
IFNC directives to accomplish this as follows:
XYZ MACRO
.
. code that should always be generated
.
IFNC &2,YES
EXITM
ENDIF
.
. code that is only sometimes generated
.
ENDM
The following calls would result in the second part being expanded or
producing code:
while all of the following would result in the second part not being
expanded:
- 41 -
TSC 6809 Assembler
where the <dup count> is the number of times the code should be
duplicated. The <dup count> may be any valid expression, but must be in
the range of 1 to 255 decimal. Note that DUP-ENDD clauses may NOT be
nested. That is to say, one DUP-ENDD clause may not be placed inside
another.
ASLDX MACRO
DUP &l
ASLB
ROLA
ENDD
ENDM
Now to shift the ’D’ register left four places we call the macro with:
ASLDX 4
ASLDX 12
And so on.
- 42 -
TSC 6809 Assembler
MORE ON MACROS
TEST MACRO
LDA #$&l COMMENT FIELD IS HERE
LDB L&l
NOP PARAMETERS CAN EVEN BE
NOP SUBSTITUTED INTO
NOP COMMENTS &2
&3 OR THEY CAN BE A MNEMONIC
&4 TST M&1M OR LABEL OR INSIDE A STRING
ENDM
- 43 -
TSC 6809 Assembler
INIT MACRO
COUNT SET 0 INITIALIZE COUNTER
COUNT SET COUNT+1 BUMP BY ONE
FCB COUNT SET THE MEMORY BYTE
IF COUNT<100,-2
ENDM
If you try this macro out, you will see that it expands into quite a bit
of source if the macro expansions are being listed because the 3rd, 4th
and 5th line are expanded for each of the one hundred times through.
However, only one hundred bytes of object code are actually produced
since lines 3 and 5 don’t produce code.
SHIFT MACRO
PSHS D
LDA &l
LDB #&2
&3 ROLA
DECB
BNE &3
STA &l
PULS D
ENDMv
SHIFT FLAG,3,CALL1
PSHS D
LDA FLAG
LDB #3
CALL1 ROLA
DECB
BNE CALL1
STA FLAG
PULS D
There is no problem here, but if the macro were called again with the
same string for parameter 3 (CALL1), a multiply defined symbol error
would result. Thus any subsequent calls to SHIFT must have a unique
string for parameter 3 such as CALL2, CALL3, etc.
- 44 -
TSC 6809 Assembler
2) Macros can be nested both in calls and in definitions. That is, one
macro may call another and one macro may be defined inside another.
3) Comment lines are stripped out of macros when defined to save storage
space in the macro text buffer.
5) A macro cannot call a LIBrary file. That is, a LIB directive cannot
appear within a macro.
7) The macro name table is searched before the mnemonic table. This
means that a standard mnemonic or directive can be effectively
redefined by replacing it with a macro of the same name.
- 45 -
TSC 6809 Assembler
0 ERROR(S) DETECTED
The number of warnings are printed only if warnings have not been
suppressed by the ’W’ option on the command line and if the number is
greater than zero (ie. only if there was a warning):
- 46 -
TSC 6809 Assembler
AUTO FIELDING
- 47 -
TSC 6809 Assembler
SYMBOL TABLE
This table is where all symbols are maintained during
assembly. Each entry into the symbol table requires 8 bytes, 6
for the name and two for the address or value associated with
it. This assembler uses a hashed symbol table technique which
can mean that symbols are pseudo-randomly scattered throughout
the table. This method is very fast but has one drawback -
the assembler is usually not able to completely fill all
positions in the table. Thus a symbol table full error
message does not necessarily mean that every position in the
table is really full. It simply means the assembler was
unable to put any more symbols in the table due to the hashing
technique used. The larger the table, the faster the hashing
method will execute and accordingly, the faster the assembler
will run. If possible, it is good to have 50% more space in
the symbol table than will be required to actually hold the
number of symbols in a program.
SOURCE BUFFER
This is the buffer which holds the source program to be
assembled. To gain speed, the assembler reads as many lines as
it can into this buffer all at once. The assembly operation
is carried out on each buffer individually. This buffer may
be any size so long as it will hold the longest line that may
be encountered in the source. There must also be a reserved
256-byte overflow area directly following the end of the
source buffer.
- 48 -
TSC 6809 Assembler
Then
- 49 -
TSC 6809 Assembler
+++ASMB,<filename>,+<options>,+<prm.A>,<prm.B>,<prm.C>
- 50 -
TSC 6809 Assembler
END
+++ASMB,FILE,+BGDS,+1
(assuming the file is very creatively called, ’FILE’), we would see the
following assembled output:
IFN (1=0)1(1=1)
ERR NOT A VALID PORT NUMBER
ELSE
IF l=0
ACIA EQU $E000
ELSE
E004 ACIA EQU $E004
ENDIF
ENDIF
END
0 ERROR(S) DETECTED
- 51 -
TSC 6809 Assembler
S1BBAAAADDDDDDDDDD......DDDDCC
where
S1 is a record start marker
BB is a byte count which includes all bytes
in the record past the byte count itself
AAAA is the load address of the first data byte
DD is the actual data
CC is a checksum equivalent to the one’s
complement of the modulo 256 sum of all
bytes preceding the checksum (except the S1)
- 52 -
TSC 6809 Assembler
The assembler supports warning messages and two types of error messages:
fatal and non-fatal. A fatal error is one which will cause an immediate
termination of the assembly such as not enough memory. A non-fatal
error results in an error message being inserted into the listing and
some sort of default code being assembled if the error is in a code
producing line. The assembly is allowed to continue on non-fatal
errors. Warning messages are handled much like non-fatal errors: the
message is inserted in the output listing and the assembly is allowed to
continue. These warning messages may be suppressed by the ’W’ option in
the command line. Error messages may not be suppressed.
UNDEFINED SYMBOL
MULTIPLY DEFINED SYMBOL
UNRECOGNIZABLE MNEMONIC OR MACRO
ILLEGAL LABEL
ILLEGAL OPERAND
RELATIVE BRANCH TOO LONG
SYNTAX ERROR
ILLEGAL INDEXED MODE
ILLEGAL CONSTANT
ILLEGAL OPTION
OPERAND OVERFLOW!
OVERFLOW!
UNBALANCED CLAUSE
UNDEFINED IN PASS 1
NOT ALLOWED IN THIS CONTEXT
MACRO EXISTS
PHASING ERROR DETECTED
- 53 -
TSC 6809 Assembler
The first three are associated with errors in the command line. The
INSUFFICIENT MEMORY message is issued when automatic table setup is
enabled and there is not at least 3K of buffer area. The MACRO OVERFLOW
message occurs when any of the macro buffers is overflowed.
- 54 -
TSC 6809 Assembler
In general, if you have FLEX up and running and have at least 16K of
user memory, there will be no need for any adapting whatsoever. Some
users, however, always feel the need to modify certain things and this
section describes how to make all the changes which we felt might be
desired (and which would be feasible). With the exception of MEMEND,
these changes must all be made to the object code of the assembler.
This can be done by loading the assembler (with a GET ASMB.CMD command),
making the desired changes in memory, and saving the result on disk
(with the SAVE command).
MEMEND
If using the automatic table setup which the assembler
performs for you, the MEMEND value in FLEX should be set to
the last address which the assembler should use. FLEX
initializes MEMEND to the actual end of user memory. You may
have an application where you don’t want this to be the case.
If so, set MEMEND manually before executing the assembler.
EXIT ADDRESS
- 55 -
TSC 6809 Assembler
TAPE CONTROL
- 56 -
TSC 6809 Assembler
NOTES:
1) The Macro Name Table and the Symbol Table must be an even
multiple of 8 bytes in size!
- 57 -