Hardware Reference
In-Depth Information
Example 2.9
Write an instruction sequence to add the BCD numbers stored at memory locations $1000
and $1001 and store the sum at $1010.
Solution:
ldaa $1000 ; load the first BCD number in A
adda $1001 ; perform addition
daa ; decimal adjust the sum in A
staa $1010 ; save the sum
Multiple-byte BCD numbers can be added and the correct result can be obtained by execut-
ing the daa instruction immediately after the addition of each byte.
2.5.6 Multiplication and Division
The HCS12 provides three multiply and five divide instructions. A brief description of
these instructions is shown in Table 2.1.
The emul instruction multiplies the 16-bit unsigned integers stored in accumulator D and
index register Y and leaves the product in these two registers. The upper 16 bits of the product
are in Y, whereas the lower 16 bits are in D.
The mul instruction multiplies the 8-bit unsigned integer in accumulator A by the 8-bit un-
signed integer in accumulator B to obtain a 16-bit unsigned result in double accumulator D. The
upper byte of the product is in accumulator A, whereas the lower byte of the product is in B.
Mnemonic
Function
Operation
emul
emuls
mul
Unsigned 16 by 16 multiply
Signed 16 by 16 multiply
Unsigned 8 by 8 multiply
(D) × (Y) Y:D
(D) × (Y)
Y:D
(A) × (B)
A:B
(Y:D) ÷ (X)
Quotient
ediv
Unsigned 32 by 16 divide
Y
Remainder D
(Y:D) ÷ (X)
Quotient
edivs
Signed 32 by 16 divide
Y
Remainder D
(D) ÷ (X)
fdiv
16 by 16 fractional divide
X
Remainder
D
idiv
Unsigned 16 by 16 integer
divide
Signed 16 by 16 integer
divide
(D) ÷ (X)
X
Remainder
D
idivs
(D) ÷ (X)
X
Remainder D
Table 2.1 Summary of 68HC12 multiply and divide instructions
 
 
Search WWH ::




Custom Search