Page 59 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 59
36 Chapter 2 The Instruction Set
Table 2.5. Arithmetic Instructions That Do Not Use an Effective Address
Multiplication can be done by addition and shifting almost as multiplication is done
by hand, but to save hardware, the product is shifted rather than shifting the multiplier to
be added to it. Figure 2.6 multiplies a 4-bit unsigned number 0110 by another 4-bit
number 1010, to get an 8-bit product. First, because the most significant bit of the
multiplier 1010 is one, add the number 0110 into the initial product 0, then shift the
product one bit left, twice, and then add the number 0110 into the product, and shift the
product one bit left. The answer is 00111100.
Actually, modern microcontrollers execute several shift-and-add operations in one
clock cycle. Thus, EMUL, which multiplies a 16-bit by a 16-bit unsigned number, takes
only three clock cycles. Signed multiplication sign extends its multiplier rather than
filling with zero, and it treats the sign bit differently. Therefore use the EMULS
instruction for signed numbers. These remarks apply analogously to the division
instructions EDIV and EDIVS. The other instructions: EDIV, EDIVS, EMULS, FDIV,
IDIV, IDIVS r and MUL, are similarly used. Note that after division, the remainder is in
Figure 2.7. Program Segment for 16-Bit Unsigned Multiplication