Goal for Today

Arithmetic

COMP375 Computer Architecture and O d Organization i ti

• Create logic gates that perform arithmetic

Elementary School

17 +7 24 010001 +000111 011000

1 Bit Adder

• A one bit adder has three inputs, numbers A and B and Carry in. There are two outputs, the Sum and Carry out. t t th S dC t A B

You add two numbers together. If the sum is greater than the number base, you add one to the next column. When you add two numbers, you may also have to add the carry from the column to the right.

Cout

one bit adder

Cin

Sum

COMP375

1

Arithmetic Circuits

Multiple Bit Adder

1 bit Adder Truth Table

A

B

A

B

A

B

Cout

one bit adder

one bit adder

one bit adder

Sum

Sum

Sum

figure from textbook

Addition Sum

A’ B’ Cin’ Cin 0 1 A’ B 1 0 A B 0 1 A B’ 1 0 Cin’ Cin

Addition Carry Out

A’ B’ 0 0 A’ B 0 1 A B 1 1 A B’ 0 1

Sum = A’BC’ + AB’C’ + A’B’C + ABC

Cout = AB + BC + AC

COMP375

2

Arithmetic Circuits

One bit adder

01000 + 01001 10001

(8) (9)

Overflow

• If operands are too big, then sum cannot be represented as an n-bit 2’s complement number. carry into sign bit carry out of sign bit

(-15)

11000 + 10111 01111

(-8) (-9) (+15)

• We have overflow if:

– signs of both operands are the same and same, – sign of sum is different.

• Another test -- easy for hardware:

– carry into left most bit does not equal carry out

Detecting Overflow

Intel Status Register

• When the carry into the sign bit does not match the carry out, there is an overflow

COMP375

3

Arithmetic Circuits

Saving Status

Status flag Overflow Sign Zero Carry Detection XOR of carry into and out of the sign bit Copy of the sign bit NOR of all result bits Carry into the sign bit

Intel Status Register

• The status register records the results of executing the instruction. ti th i t ti • Performing arithmetic sets the status register. • The compare instruction does a subtraction, subtraction but doesn t store the results. doesn’t results It just sets the status flags. • All jump instructions are based on the status register

1 Bit Subtracter

• A one bit subtracter has three inputs, numbers X and Y and Borrow in. There are t two outputs, the Diff t t th Difference and B d Borrow out. X Y X 0 0 0 0 1 1 1 1

X-Y Subtracter Truth Table

Y Bin Bout 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 0 1 0 1 0 0 1 1 1 Diff 0 1 1 0 1 0 0 1

Diff = X’YBin’ + XY’ Bin’ + X’Y’ Bin + XYBin

X’ Y’ X’ Y X Y X Y’

Bin’ Bin

0 1

1 0

0 1

1 0

Borrowout

one bit subtract

Borrowin

Difference

COMP375

4

Arithmetic Circuits

What is the equation for Bout?

1. 2. 3. 4. Bout = XY + Bin Bout = YBin + XBin Bout = XBin’+YBin’+XY Bout = XY + X’Bin 25% 25% 25% 25%

The equation for Bout

X 0 0 0 0 1 1 1 1 Y Bin Bout 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 0 1 0 1 0 0 1 1 1 Diff 0 1 1 0 1 0 0 1

Bout= XBin’ + YBin’ + XY

X’ Y’ X’ Y X Y X Y’

Bin’ Bin

0 0

1 0

1 1

1 0

...

X B in ’+ Y ...

B i.. .

Y B in

+

X Y

=

B ou t=

B ou t

=

Subtraction

• Instead of building a separate subtraction circuit, you can add the negative of the operand. • To make a twos complement number negative, you must invert the bits and add one • A NOT gate can be used to invert all the bits. • Setting the Carry In on the rightmost bit will add one to the result. A+B’+1 = A + (B’+1) = A + (-B) = A - B

B ou t

B ou t

=

X Y

+

X’ ..

+

.

Draw a Subtraction Circuit

• Using one bit adder boxes and OR, AND or NOT gates, draw the logic diagram for a four bit twos complement A - B subtraction circuit. A B

Carryout

one bit adder

Carryin

COMP375

5

Arithmetic Circuits

Subtraction Circuit

Propagation Delay

• To make a 32 bit adder, you can use 32 one bit adders. dd • The left most bit cannot be computed until all of the other bits are computed so that the...