Integer Addition, Subtraction, and Multiplication - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Integer Addition, Subtraction, and Multiplication

Description:

If it's 1, you have to compute its 2's complement. ... Multiplication: In general, if the multiplicand has n bits and the multiplier ... – PowerPoint PPT presentation

Number of Views:75
Avg rating:3.0/5.0
Slides: 15
Provided by: egBuc
Category:

less

Transcript and Presenter's Notes

Title: Integer Addition, Subtraction, and Multiplication


1
  • Integer Addition, Subtraction, and Multiplication

2
Operations on 2s Complement
  • Absolute value Look at the leftmost bit, if its
    0, youre done. If its 1, you have to compute
    its 2s complement.

Addition Start adding the bits of the two
operands, from the rightmost position, carrying
over any excess to the position immediately to
the left. Youre done when you have added all the
bits in the representation. Note that overflow
can occur
3
Operations on 2s Complement
  • Unary minus Given a number, you simply compute
    its 2s complement.

Subtraction Note that (A-B) is the same as
(A(-B)), so this operation can be done in two
steps a sign inversion and an addition. Just as
in addition, overflow can occur
4
Operations on 2s Complement
Multiplication If the multiplier is a power of
2, the operation is trivial. Otherwise, we have
to define an algorithm.
Example
1011 1110 0000
x
1011
1011
1011

10011010
5
Signing The Result of Unsigned Multiplication and
Division
  • The algorithms well see ahead compute the
    unsigned product or quotient of two operands. To
    do signed multiplication and division, we can
    record the signs of the operands, do the unsigned
    operation and then correct the sign of the result.

6
Multiplication In general, if the multiplicand
has n bits and the multiplier has m bits, the
product will have (nm) bits. Note whats going
on we go through each bit in the multiplier and
performing a sequence of left-shifts and
additions. This is an indication that to
implement multiplication in hardware, one needs a
shift-register and an adder. What about the
signs of the operands and the sign of the result?
7
An Algorithm for Multiplication
Both operands are 32-bits long. What is the
size of the product? How many registers are
needed to implement this in hardware? In
general, how many repetitions are needed by this
algorithm?
8
A Simpler (?) Flowchart for the Basic
Multiplication Algorithm
start
1
0
test
CCA
Altlt1
Bgtgt1
no
reps?
yes
done
9
Another Algorithm for Multiplication
10
Operations on 2s Complement
Division It the multiplier is a power of 2, the
operation is trivial. Otherwise, we have to
define an algorithm, but first, lets think a
little bit. Quotient How many times does the
divisor fit into the dividend? Remainder After
the largest multiple of the divisor that fits in
the dividend has been subtracted from the
dividend, whats left?
11
  • Division

1001
1000
1001010
-1000
1010
-1000
10
We do subtractions and shifts
12
A Simpler (?) Flowchart for the Basic Division
Algorithm
start
1001
RR-D
1000
1001010
yes
no
-1000

1010
-1000
RRD Qltlt1(0)
10
Qltlt1(1)
2n bits
(0)Dgtgt1
D
divisor 0000
no
n1 reps?
R
0000 dividend
yes
Q
0000
done
n bits
13
7 2
n4
14
Signing The Remainder
To avoid such confusion, we postulate
Write a Comment
User Comments (0)
About PowerShow.com