Hardware Reference
In-Depth Information
ldd
$1005
; place the dividend in D
ldx
$1020
; place the divisor in X
idivs
; perform the signed division
stx
$1030
; save the quotient
std
$1032
; save the remainder
Because most arithmetic operations can be performed only on accumulators, we need to
transfer the contents of index register X to D so that further division on the quotient can be
performed. The HCS12 provides two exchange instructions in addition to the TFR instruction
for this purpose.
The xgdx instruction exchanges the contents of accumulator D and index register X.
The xgdy instruction exchanges the contents of accumulator D and index register Y.
The HCS12 provides instructions for performing unsigned 8-bit by 8-bit and both signed
and unsigned 16-bit by 16-bit multiplications. Since the HCS12 is a 16-bit microcontroller, we
expect that it will be used to perform complicated operations in many sophisticated applica-
tions. Performing 32-bit by 32-bit multiplication will be one of them.
Since there is no 32-bit by 32-bit multiplication instruction, we have to break a 32-bit num-
ber into two 16-bit halves and use the 16-bit by 16-bit multiply instruction to synthesize the
operation. Assume that M and N are the multiplicand and the multiplier, respectively. These
two numbers can be broken down as follows:
M 5 M H M L
N 5 N H N L
where M H and N H are the upper 16 bits and M L and N L are the lower 16 bits of M and N, respec-
tively. Four 16-bit by 16-bit multiplications are performed, and then their partial products are
added together, as shown in Figure 2.3.
The procedure is as follows:
Step 1
Allocate 8 bytes to hold the product. Assume these 8 bytes are located at P, P11, . . . , and
P17.
Step 2
Compute the partial product M L N L (in Y:D) and save it at locations P14,P17.
Step 3
Compute the partial product M H N H (in Y:D) and save it at locations P,P13.
Step 4
Compute the partial product M H N L (in Y:D) and add it to memory locations P12,P15.
The C flag may be set to 1 after this addition.
Step 5
Add the C flag to memory location P11 using the adca (or adcb) instruction. This addition
may also set the C flag to 1. So, again, add the C flag to memory location P.
Step 6
Generate the partial product M L N H (in Y:D) and add it to memory locations P12,P15.
The carry flag may be set to 1, so add the C flag to memory location P11 and then add it
to memory location P.
 
Search WWH ::




Custom Search