Chapter 6. Programming Techniques
Note that GENAO could add any combination
of
the parameters with no change to the parameters themselves.
The sequence:
PLlST:
LXI
CALL
OW
OW
OW
H,PLlST
GENAO
PARM4
PARM1
OFFFFH
would
cause
PARM1
and
PARM4
to
be
added, no matter where
in
memory they might
be
located (excluding
addresses above
FFOOH).
Many
variations of parameter passing are possible. For example,
if
it
is
necessary to allow parameters to
be
stored at any address, a calling program can
pass
the total number of parameters
as
the first parameter; the
subroutine then
loads this first parameter into a register and
uses
it
as
a counter to determine when
all
param-
eters had been accepted.
SOFTWARE
MULTIPLY
AND
DIVIDE
The multiplication
of
two unsigned 8-bit data bytes
may
be accomplished
by
one
of
two techniques: repetitive
addition, or
use
of
a register shifting operation.
Repetitive addition provides the
simplest, but slowest, form
of
multiplication. For example, 2AH*74H
may
be
generated
by
adding 74H to the (initially zeroed) accumulator 2AH times.
Shift operations provide faster
multiplication. Shifting a byte left one bit
is
equivalent to multiplying
by
2,
and
shifting a byte right one bit
is
equivalent to dividing
by
2,.
The following process
will
produce the correct 2-byte
result of multiplying a one byte multiplicand
by
a one byte multiplier:
A.
Test the least significant bit
of
multiplier.
If
zero,
go
to step
b.
If
one, add the
multiplicand to the most significant byte of the result.
B.
Shift the entire two-byte result right one bit position.
C.
Repeat steps a and b until
all
8 bits of the multiplier
have
been tested.
For
example, consider the multiplication: 2AH*3CH=908H
Step 1:
Step 2:
Step
3:
Test multiplier
O-bit;
it
is
0,
so
shift 16-bit result right one bit.
Test
multiplier l-bit; it
is
0,
so
shift 16-bit result right one bit.
Test
multiplier 2-bit; it
is
1,
so
add
2AH
to high-order byte
of
result and shift 16-bit
result right one bit.
6·7