







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Instruction sequences and explanations for multiplying and dividing signed and unsigned 16-bit and 32-bit numbers using the 68hc12 microcontroller. It includes examples and illustrations of the multiplication process.
Typology: Exams
1 / 13
This page cannot be seen from the preview
Don't miss anything!








Example 2.10’
Write an instruction sequence to multiply the 16-bit numbers
stored at $800-$801 and $802-$803 and store the product at $900-$903. ldy^
$^
;load 1
st^ operand into Y
ldd^
$^
;load 2
nd^ operand into D
emul^
; Multiplying the numbers assuming unsigned numbers
sty^
$^
;storing the upper 16 bits
std^
$^
;storing the lower 16 bits
st^2 operand LSBst^2 operand MSBst^1 operand LSBst 1 operand MSB
$803^ $802^ $801^ $
Original Operands in Memory
emul
$903^ $902^ $901^ $
Product in Memory
D^ Y
D : Y
LSBs MSBs
Example 2.
Write an instruction sequence to divide the signed 16-bit number
stored at $1005-$1006 by the signed 16-bit number stored at $1020-$1021 andstore the quotient and remainder at $1030-$1031 and $1032-$1033, respectively.
LSB of Rem^ MSB of Rem
$1033$
LSB of Divisor^ MSB of Divisor
$1021$
idivs
LSB of Quotient^ MSB of Quotient
$1031$
LSB of Dividend^ MSB of Dividend
$1006$
D^ X^
D X
ldd^
$
;load the dividend into D
ldx^
$
;load the divisor into X
idivs^
; perform signed division
stx^
$
;storing the quotient
std^
$^
;storing the remainder
Example 2.
Write a program to multiply two unsigned 32-bit numbers
stored at M~M+3 and N~N+3, respectively and store the product at P~P+7. Solution:
org^
ds.b^
;Multiplicand 4 bytes
ds.b^
;Multiplier 4 bytes
ds.b^
;Product 8 bytes
org^
ldd^
;place M
in DL^
ldy^
;place N
in YL^
emul^
; compute M
sty^
std^
ldd^
ldy^
emul^
; compute M
sty^
std^
ldd^
ldy^
emul^
; compute M
16-bit P ~ P+1^ P+2 ~ P+
P+4 ~ P+ upper half^ P+6 ~ P+ upper halfupper half upper half lower half
lower halflower half
lower half
Address
partial product M
NLL partial product M
NHL partial product M
NLH partial product M
NHH Final product M
× N
msb^
lsb
Note: msb stands for most significant byte and lsb for least significant byte
16-bit Figure 2.3 Unsigned 32-bit by 32-bit multiplication 16-bit
16-bit
Example 2.12 contd…; add M
N^ to memory locations P+2~P+5H L^
addd^
std^
tfr^
adcb^
stab^
adca^
staa^
; propagate carry to the most significant byte
ldaa^
adca^
; add carry to the location at P+
staa^
ldaa^
; add carry to the location at P
adca^
staa^
; compute M
N^ L H ldd
ldy^
emul
16-bit P ~ P+^
P+2 ~ P+
P+4 ~ P+
P+6 ~ P+ upper half upper halfupper half upper half
lower half
lower halflower half
lower half
Address
partial product M
N^ LL partial product M
N^ HL partial product M
N^ LH partial product M
N^ HH Final product M × N
msb^
lsb
Note: msb stands for most significant byte and lsb for least significant byte
16-bit Figure 2.3 Unsigned 32-bit by 32-bit multiplication 16-bit
16-bit
adds the BCD numbers stored at $800 and $801 and saves the sum at $802.
Example 2.13’
Write a program to convert the 16-bit number stored at $800-$801 to
BCD format and store the result at $900-$904. Convert each BCD digit into its ASCIIcode and store it in one byte. Solution: -^ A binary number can be converted to BCD format by using repeated division by 10.-^ The largest 16-bit binary number is 65535 which has five decimal digits.-^ The first division by 10 obtains the least significant digit, the second division by 10obtains the second least significant digit, and so on.
org^
data^
dc.w^
; data to be tested
org^
result ds.b
; reserve bytes to store the result
org^
ldd^
data ldy^
#result ldx^
idivaddb^
; convert the digit into ASCII code
stab^
; save the least significant digit
xgdxldx^