Computer Systems: Arithmetic Programming - Multiplication and Division Instructions, Exams of Microcomputers

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

Pre 2010

Uploaded on 07/30/2009

koofers-user-82o
koofers-user-82o 🇺🇸

10 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ECE 3120
Computer Systems
Arithmetic Programming
Manjeera Jeedigunta
http://blogs.cae.tntech.edu/msjeedigun21
Tel: 931-372-6181, Prescott Hall 120
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Computer Systems: Arithmetic Programming - Multiplication and Division Instructions and more Exams Microcomputers in PDF only on Docsity!

ECE 3120

Computer Systems

Arithmetic Programming

Manjeera Jeedigunta

http://blogs.cae.tntech.edu/msjeedigun

Email: [email protected]: 931-372-6181, Prescott Hall 120

†^ Today:^ „

Multiplication and Division Examples „ BCD

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^

M^

ds.b^

;Multiplicand 4 bytes

N^

ds.b^

;Multiplier 4 bytes

P^

ds.b^

;Product 8 bytes

org^

ldd^

M+^

;place M

in DL^

ldy^

N+^

;place N

in YL^

emul^

; compute M

N^ L L

sty^

P+

std^

P+

ldd^

M

ldy^

N

emul^

; compute M

N^ HH

sty^

P

std^

P+

ldd^

M

ldy^

N+

emul^

; compute M

N^ HL

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^

P+

std^

P+

tfr^

Y,D

adcb^

P+

stab^

P+

adca^

P+

staa^

P+

; propagate carry to the most significant byte

ldaa^

P+

adca^

#^

; add carry to the location at P+

staa^

P+^
;^

ldaa^

P^

; add carry to the location at P

adca^

#^
;^

staa^

P^
;^

; compute M

N^ L H ldd

M+

ldy^

N

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

BCD Numbers and Addition -^ Each digit is encoded by 4 bits-^ Two digits are packed into one byte-^ The addition of two BCD numbers is performed by binary addition andan adjust operation using the DAA instruction.-^ The instruction DAA can be applied after the instructions ADDA,ADCA, and ABA.-^ Simplifies I/O conversionFor example, the instruction sequence

LDAA
ADDA
DAASTAA

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^

4,Y^

; save the least significant digit

xgdxldx^

  • Next… † Program Loops † Read Chapter 2.