CSE 233: COMPUTER ORGANIZATION
& ARCHITECTURE
Tamanna Haque Nipa
Assistant Professor
Dept. of CSE
Stamford University Bangladesh
INTEGER ARITHMETIC
Negation
Addition
Subtraction
Multiplication
Division
Comparison
2
NEGATION-EXAMPLE
-7 -6
0111 = 7 0110 = 6
1000 = (7)0 1’s Complement 1001 = (6)0 1’s Complement
1000 + 1 = 2’s Complement 1001 + 1 = 2’s Complement
1001 = -7 1010 = -6
3
ADDITION-EXAMPLE
5+4 (-7) + (-6)
1 0 0 0 0 0
Cin =0 Cin =0
0 1 0 1 = +5 1 0 0 1 = -7
0 1 0 0 = +4 1 0 1 0 = -6
0 1 0 0 1 = +9 1 0 0 1 1 = -13
• Overflow occurs as 5 and 4 • Overflow occurs as -6 and
both are +ve but the result -7 both are -ve but the
is –ve (1001). To correct the result is +ve (0011). To
result, we need to consider correct the result, we need
the carry bit. to consider the carry bit.
4
ADDITION-EXAMPLE Overflow:
(+ve) + (+ve) = (-ve)
16+ 4 (-ve) + (-ve) = (+ve)
Cin =0
0 1 0 0 0 0 = +16
0 0 0 1 0 0 = +4
0 0 1 0 1 0 0 = +20
• Overflow has not occurred as 16 and 4 both are +ve and the
result is +ve. The result will not consider the carry bit.
5
SUBTRACTION-EXAMPLE
7 – 7 = 7 + (-7) (-6) - (-4) = -6 + 4
1 1 1 0 0 0
Cin =0 Cin =0
0 1 1 1 = +7 1 0 1 0 = -6
1 0 0 1 = -7 0 1 0 0 = +4
1 0 0 0 0 = +0 0 1 1 1 0 = -2
• Overflow has not occurred • Overflow has not occurred
as 7 and -7 both are not as -6 and +4 both are not
with same sign. The correct with same sign. The correct
result is 0000. We will result is 1110. We will
avoid the carry bit. avoid the carry bit.
6
OVERFLOW AND CARRY
Carry: After addition if any extra bit is found that is
carry.
Overflow: If the operands have the same sign but the
result shows the opposite sign
⚫ Result is larger that what can be stored with the word
otherwise error occurs
⚫ Increase word size considering the carry bit
⚫ When overflow occurs, ALU must signal this fact so that
no attempt is made to use the result.
7
ADDER-SUBTRACTOR
Subtraction: F = A-B = A + (-B) = A + B0 + 1
Example: -9
-8 4 2 1
9 = 1001 X 1 0 0 1
-16 8 4 2 1
9 = 01001 – 5 bit 0 1 0 0 1
Negative values are represented by 2’s complement method
2 Steps: a) 1’s complement of 9 --- 10110 = (9)0
b) add 1 with it --- 10111 (-9)
-B = B0 + 1 8
ADDER-SUBTRACTOR
Addition: F = A + B
Cin =0 1 1 1
Cin =0
A3 A2 A1 A0 0 1 0 1 = 5
B3 B2 B1 B0 0 1 1 1 = 7
Cout S3 S2 S1 S0 1 1 0 0 = 12
Cout = 0
Subtraction: F = A-B = A + (-B) = A + B0 + 1
Cin =1 0 0 1
Cin =1
A3 A2 A1 A0 0 1 0 1 = 5
(B3 B2 B1 B0)0 1 0 0 0 = (7)0 9
Cout S3 S2 S1 S0 1 1 1 0 = -2
Cout = 0
ADDER-SUBTRACTOR CIRCUIT
How to implement B0 ?
0 1 1 1 = 7
A B F=A⊕B
XOR with 1 1 1 1 1
0 0 0
1 0 0 0 = (7)0
0 1 1
1 0 1
1 1 0
0 1 1 1 = 7
XOR with 0 0 0 0 0
0 1 1 1 = 7
10
ADDER-SUBTRACTOR CIRCUIT
0111
B3 B2 B1 B0
0101
A3 A2 A1 A0
0111
Cout = 0
0111 + 0101 + 0
Cin = 0
4 bit Full Adder
S3 S2 S1 S0 For Add Cin=0
1100 11
ADDER-SUBTRACTOR CIRCUIT
0111
B3 B2 B1 B0
0101
A3 A2 A1 A0
1000
Cout = 0
1000 + 0101 + 1
Cin = 1
4 bit Full Adder
S3 S2 S1 S0 For Subtraction Cin=1
1110 12