TC1796
System Units (Vol. 1 of 2)
Peripheral Control Processor (PCP)
User’s Manual
11-122
V2.0, 2007-07
PCP, V2.0
11.13.4
Implementing Divide Algorithms
As discussed in
, a divide algorithm
must
always start with a DINIT
instruction followed by a number of DSTEP instructions (up to four depending on the
data width that is required). Prior to execution of any DSTEP instruction, R0 always
contains either 0 (if this is the first DSTEP instruction in a divide sequence R0 contains
0 due to the preceding DINIT instruction), or the remainder from the previous DSTEP
instruction). The dividend to be used in this step is generated in R0 by taking 256
×
the
remainder of the last DSTEP instruction (R0 << 8) and adding the most significant byte
of Rb (Rb >> 24) as the LSB of the new dividend.
Since the remainder of the last DSTEP instruction is by definition always less than the
divisor (Ra), it can be guaranteed that the result of the division of the dividend (calculated
as above) by the divisor (Ra) can always be contained within an 8-bit result. The
description given at
only holds true under this condition. If the restrictions on
the use of the DSTEP instruction (specified at
) are adhered to, the above
condition will always be met and this description of the instruction is correct. Failure to
adhere to these conditions will lead to invalid results, which are outside the scope of this
document.
During execution of a divide sequence, Rb is used both to compile the final divide result
and to hold the remnants of the original dividend. For example, in a 32-/32-bit divide
sequence (which consists of 4 DSTEP instructions - see below), Rb will have the
following content:
•
After the 1
st
DSTEP instruction:
The least significant 3 bytes (24 bits) of the original 32-bit dividend (held in the most
significant 3 bytes of Rb) and the most significant byte of the final result (held in the
least significant byte of Rb).
•
After the 2
nd
DSTEP instruction:
The least significant 2 bytes (16 bits) of the original 32-bit dividend (held in the most
significant 2 bytes of Rb) and the most significant 2 bytes of the final result (held in
the least significant 2 bytes of Rb).
•
After the 3
rd
DSTEP instruction:
The least significant byte of the original 32-bit dividend (held in the most significant
byte of Rb) and the most significant 3 bytes of the final result (held in the least
significant 3 bytes of Rb).
•
After the final DSTEP instruction:
The 32 bit final result.
Note that the DSTEP instruction
always
uses the divisor as a 32 bit value. In any divide
sequence, the dividend can be 8, 16, 24 or 32 bits (according to the number of DSTEP
instructions in the sequence) but the divisor is
always
32 bits. Prior to the DINIT
instruction, the dividend must always occupy the appropriate most significant bits within
the 32-bit dividend register (Rb).