Operating instructions

Listing 1.
MICRO
--
The 6502 Journal
Sample Sweet·16 Program
LD@
(5)
ST@
(6)
LD
(4)
CPR
(5)
BP
(MOVE)
RTN
45 MOVE
56
24
05
04
FA
00
Sweet-16 can also
be
used more
conveniently with
this
set
of
macros.
They make the assembly source easier
to read, and remove the burden
of
hand
assembly from the Sweet-16 program-
mer.
The reader is urged
to
learn more
about
the
macro
capabilities
of
assemblers and the labor-saving uses to
which they may
be
applied.
.DE
0
.DE
1
.DE 2
.DE
3
.DE
4-
.DE
5
.I1E
6
.DE
7
.DE
8
.DE
9
.DE
10
.DE
11
.DE
12
.DE
13
.DE
14-
.DE
15
.ES
.MII
(
REG
ADDR)
.BY
$10H\EG
.SE
AIiDF<
.ME
•
MIl
(REG)
.BY
$20H<EG
.ME
.MII
(REG)
.BY
$30tl~EG
.ME
.MII
(REG)
.BY
$40tREG
.ME
.MII
(REG)
.BY
$50tF<EG
.ME
.MD
(REG)
January, 1980
@SW16
SETR
(5
$800)
SETR (4 $BFF)
SETR
(6
$400)
0002
RO
0003
R1
0004
R'i
.:..
0005
f<3
0006
R4
0007
R5
0(>08
R6
0009
R7
0010
R8
0011
Rtf
0012
R10
0013
R11
0014-
R:l.2
0015
R13
0016
R14
0017
R15
0018
0019
!!
!SETR
0020
0021
0022
0023
!LD
0024
0025
0026
!ST
0027
0028
0029
!LD@
0030
0031
0032
! !
!ST@
0033
0034
0035
!LDD@
.Arithmetic may be performed
on dummy arguments:
!!!LD
.MD
(REG)
.BY
$20
+
REG
.ME
20
89
F6
15
00 08
14
FF
OB
16
00
04
The following program allows the
second
text
page
of
APPLE
II
memory to
be
copied
into
the
first
text page. The
assembled code is shown to the left.
This fact is crucial to the success
of
the
macros.
.BY
=
-LOC+
1
The remainder
of
the macro defini-
tions
are simple and straightforward. A
couple
of
points
to
note are:
IFM
=-LOC
.Defining @SW16 as JSR SW16
makes
the
macro
@SW16
looklike a
"new"
assembler
directive. It says:
Please
switch
to
Sweet-16
These
instructions
are analogous
to
the corresponding
instructions
follow-
ing the IFP directive. The reason
for
us-
ing
both
an
IFP and
an
IFM directive is
that
the label
or
location referenced by
the dummy argument 'LOC' may turn out
to
be
either ahead
of
(minus result
for
=
-LOC)
or
behind (positive result
for
=
-LOC)
the instruction which invokes
the RELBR macro.
character
'=
'.
The location
counter
represents the address
of
the instruc-
tion being assembled.
BY
LOC-
=-1
20:28
The directive .BY
instructs
the
assembler to evaluate the expression
following and
to
assemble a single BYte
of
code from the resulting value. The
ex-
pression
LOC-
=
-1
computes a value
which is the distance from the symbol
referenced by 'LOC' to the current loca-
tion in the object code. This value is con-
verted by the expression
to
a negative
number and adjusted
by
1 to account
for
the fact
that
the current byte
of
object
has not yet been emitted by the
assembler. Note
that
there is a bug in
the definition: if the value
LOC-
=
-1
is
less than
-128
then
an
erroneous value
will
be
assembled. This means
that
the
user
of
the macro set is responsible for
avoiding relative branches
that
are out
of
range. Note also
that
the values com-
puted by expressions are in
16
bit,
twos
complement representation.
If
such a
value is assembled using a .BY directive,
the assembler will use the least signifi-
cant 8
bits
(low byte)
of
the result.
This line marks the end
of
the scope
of
the IFP conditional assembly direc-
tive used earlier.
This line has the same intention as the
IFP line, except that it tests the result of
the
expression'
=
-LOC'
for a negative
or Minus value. It then does or does not
assemble the
instructions
following the
IFM line and up to the matching
* *
*,
depending
on
the outcome
of
the evalua-
tion.