Docsity

Binary Arithmetic - Intro to Computer Architecture - Lecture Slides, Slides of Computer Architecture and Organization

Partial preview of the text

Download Binary Arithmetic - Intro to Computer Architecture - Lecture Slides and more Slides Computer Architecture and Organization in PDF only on Docsity!

Binary Arithmetic

Two's Complement

 Most significant bit represents sign.

0 = positive

1 = negative

 Positive numbers behave exactly like unsigned

integers.

 Negative numbers are added to the negative

value of the most significant bit.

Binary Addition and Subtraction

 Similar to decimal addition

00 10 carry 0 011 3

0 010 2 0 101 = 5

 Subtraction can be achieved by adding a

negative.

Overflow

 Overflow occurs when the result is beyond the

possible range allowed by the number of bits.

01 00 carry

0 100 4 0 101 5 1 001 = -7 (WRONG!)

 Typically only occurs when the two left-most

carries are either 10 or 01. 11 produces no

problems.

 Can be detected with a simple XOR of the last

two carries.

Full Adders

 The drawback of half adders is that they do not

account for the carry-in from a previous bit

addition. For that, there are full adders:

S = A XOR B XOR C in

C = (A AND B) OR (C in AND (A XOR B))

Ripple Adders

 Multiple full adders can be strung together to

create a ripple adder, with the carry-out from

each going into the carry-in of the next.

Carry Lookahead Adders

 In lookahead adders each 1-bit adder first

informs the look ahead logic of two values:

G – If the bit will generate a carry. This will

happen regardless of an incoming carry if

both A and B are 1. (G = A AND B)

P – If the bit will propagate an incoming carry

into the next bit adder. This will happen if

either A or B is at least 1. (P = A OR B)

 Once P and G are known for all bit adders, it is

possible to determine incoming carries without

waiting for the full summation.

Carry Lookahead Adders

Multiplication of

Unsigned Integers

 Again, similar to decimal.

 Multiplying integers with x and y number of bits

will yield a product of bits x+y. (at most)

Example w/4-bit integers: 12 * 5 = 60

Multiply the numbers as usual for decimal, then add them. Because binary only uses 1s and 0s, a shortcut is to simply repeat the multiplicand for each 1 in the multiplier, shifted left.

Multiplicand Multiplier

Product

Fast Multiplication:

Booth's Algorithm

 Multiplying integers M * N of lengths m and n respectively, need the following values:

A = M followed by n+1 0's.

B = M' followed by n+1 0's.

P = m 0's followed by N and a 0.

 Start with P and examine 2 rightmost bits.

10 → P = P+B, shift right

01 → P = P+A, shift right

00 or 11 → shift right

 Do this n times, then drop the right most bit. P is now the product in two's complement.

Example: -5 * 7 → 1011 * 0111

A = 1011 0000 0 B = 0101 0000 0 P = 0000 0111 0

1) P=P+B 0 0 0 0 0 1 1 1 0

shift 0 1 0 1 0 1 1 1 0

  1. shift 0 0 1 0 1 0 1 1 1
  2. shift 0 0 0 1 0 1 0 1 1
  3. P=P+A 0 0 0 0 1 0 1 0 1 shift 1 0 1 1 1 0 1 0 1

Product = 1 1 0 1 1 1 0 1