Title: Module 2:
1- Module 2
- Arithmetic of Computers Arithmetic Operations
- (Book Computer Organization and Design,3ed,
David L. Patterson and John L. Hannessy, Morgan
Kaufmann Publishers)
2Introduction
- Numbers are represented by binary bits
- How are negative numbers represented?
- What is the largest number that can be
represented in a computer world? - What happens if an operation creates a number
bigger than can be represented? - What about fractions and real numbers?
- A mystery How does hardware really multiply or
divide numbers?
3Binary Numbers
4Twos Complement (32-bit)
- 0111 ... 1111 1111 1111 1111two
2,147,483,647ten - 0111 ... 1111 1111 1111 1110two
2,147,483,646ten - 0111 ... 1111 1111 1111 1101two
2,147,483,645ten - . . .
- 0000 ... 0000 0000 0000 0010two 2ten
- 0000 ... 0000 0000 0000 0001two 1ten
- 0000 ... 0000 0000 0000 0000two 0ten
- 1111 ... 1111 1111 1111 1111two -1ten
- 1111 ... 1111 1111 1111 1110two -2ten
- 1111 ... 1111 1111 1111 1101two -3ten
- . . .
- 1000 ... 0000 0000 0000 0001two
-2,147,483,647ten - 1000 ... 0000 0000 0000 0000two
-2,147,483,648ten
- To represent positive and negative numbers
- MSB - 0 means positive
- MSB - 1 means negative
Indicates sign of the integer
5Twos Complement Shortcut NegationConvert
Decimal to Twos ComplementConvert Twos
Complement to Decimal
Therefore -2 since the MSB is 1
6Binary Addition and Subtraction
6
7Detecting Overflow in Two Complement Numbers
- Overflow occurs when adding two positive numbers
and the sum is negative, or vice versa - A carry out occurred into the sign bit
Overflow conditions for addition and subtraction
8Binary Mutiplication
91st Version of Multiplication Hardware
Flows of 1st Version Multiplication
32-bit multiplicand starts at right half of
multiplicand register
Product register is initialized at 0
Multiplicand register, product register, ALU
are 64-bit wide multiplier register is 32-bit
wide
Algorithm
10Example of Multiplication 4 bits
11Signed Multiplication
- So far we have dealt with positive numbers. But
how to deal with signed numbers? - To first convert the multiplier and multiplicand
to positive numbers and then remember the
original signs - Leave the sign out of the calculation
- To negate the product only if the original signs
disagree
12Binary Division
131st Version of Division Hardware
Flows of 1st Version Division
32-bit divisor starts at left half of divisor
register
Quotient register is initialized to be 0
Remainder register is initialized with the
dividend at right
Divisor register, remainder register, ALU
are 64-bit wide quotient register is 32-bit wide
Algorithm
14Example of Division
15Signed Division
- Signed divide
- - make both divisor and dividend positive and
perform division - - negate the quotient if divisor and dividend
were of opposite signs - - make the sign of the remainder match that of
the dividend - - this ensures always
- dividend (quotient divisor) remainder
- quotient (x/y) quotient (x/y) (e.g. 7 32
1 7 32 1) -