TC1796
System Units (Vol. 1 of 2)
Peripheral Control Processor (PCP)
User’s Manual
11-123
V2.0, 2007-07
PCP, V2.0
Divide Examples
Example of a 32/32 bit divide (R5 / R3):
DINIT
R5, R3
;Initialize ready for the divide
JC
HANDLE_DIVIDE_BY_ZERO, cc_V ;V flag was set so
;jump to divide
;by zero error handler
DSTEP
R5, R3
;4 DSTEP instructions
;(4 * 8 = 32 bit
DSTEP
R5, R3
; divide)
DSTEP R5,
R3
DSTEP R5,
R3
After this sequence, R5 holds the result, R0 the remainder and R3 is unchanged.
Example of a 8/32 bit divide (R4 / R2):
RR
R4, 8
;Rotate R4 right by 8 to move
;least significant byte into
;most significant byte
DINIT
R4, R2
;Initialize ready for the divide
JC
HANDLE_DIVIDE_BY_ZERO, cc_V ;V flag was set so
;jump to divide
;by zero error handler
DSTEP
R4, R2
;DSTEP instruction
;(1 * 8 = 8 bit divide)
After this sequence, R4 holds the result, R0 the remainder and R2 is unchanged.
Note that the above example is specified as being a 8/32 bit divide rather than an 8/8 bit
divide (see comments above).
11.13.5
Implementing Multiply Algorithms
As discussed in
, a multiply algorithm
must
always start with a MINIT
instruction, followed by a number of MSTEP32 or MSTEP64 instructions. The MSTEP32
instruction is used to compile a multiplication result contained in 32 bits, discarding any
overflows. The MSTEP64 instruction is used to compile a 64-bit multiplication result with
the least significant 32 bits of the result contained in Rb and the most significant 32 bits
of the result contained in R0.
Multiply Examples
Example of a 32
×
8 bit multiply (R4
×
R1) yielding a 32 bit result (R4 = 32 bit, R1 = 8 bit):
RR
R1, 8
;Rotate least significant byte of R1 to
;most significant byte
MINIT
R1, R4
;Initialize ready for multiply