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