Arithmetic
Arithmetic
Arithmetic
Operations
1
Arithmetic
Operations
• An arithmetic logic unit (ALU) is a hardware that
performs arithmetic and logical operations
3
4
5
6
7
1-
•
operation
BITALU
Can do logical AND and logical OR
• AND operation=0
• OR
operation=1
8
32
BITALU
9
Typical symbol of an ALU
1
ADDITION
1
ADDITION
1
ADDITION
Digits are added bit by bit from right to left, with
•
carries passed to the next digit to the left.
1
ADDITION
1
OVERFLOW IN ADDITION
1
OVERFLOW IN ADDITION
Example
:
1
OVERFLOW IN ADDITION
♣ + sign indicative
+ve
♣ – sign indicate –ve.
• In computer, everything are binary
numbers,
01001 +9
11001 - 9
20
2
exampl
e
• Consider a two 4 bit positive number +9 and
+8
+9 and +8 = 01001 + 01000 =0001
010011000
010000111
21
2
exampl
e
1
ADDITION
• The MIPS solution is to have two kinds of
arithmetic instructions to recognize the two choices:
1
SUBTRACTION
Three ways
❑ Direct Method
❑ Using 1’s Complement
❑ Using 2’sComplement
2
RULES FOR BINARYSUBTRACTION
2
DIRECT
METHOD
1) Subtract the binary
number
• 110 from 1001 ( 6 from 9)
• 11 from 1000 (3 from 8)
• 01 from 10000 (1 from
16)
Answer
i) 011
ii) 101
iii) 1111
1’S COMPLEMENT
000110. Hence
Minued 1 0 1 0 11
-
1’s complement 0 0 0 1 1 0+
-
11000
1
1’S
COMPLEMENT
2) 110101 – 100101
Solution:
1’s complement of 10011 is
011010. Hence,
Minued - 110101
1’s complement of 01101
subtrahend- 0+
Carry over - 1 001111
1 +
0 1 0 0 00
2’S COMPLEMENT
• By taking 1’s complement of the number and adding
1to the least significant bit
• 2’s Complement = 1’s Complement+1
• Example : 11010
00101 +1 = 00110
Rules
• Step 1: Determine the 2’s complement of the
smaller
number
• Step 2: Add the 2’s complement to the
largernumber 8
• Step 3: If carry exist discard
2’S COMPLEMENT
1) 10110 – 11010
Solution:
2’s complement of 11010 is (00101 + 1) i.e.
00110. Hence
Minued - 1 0 1 1 0
a)0 1 1 1 1 b)0 1 1 1 1
11100-10100+
10011 10011
In a) : subtract directly.
In b) : 2’s complement of second number isadded to