Professional Documents
Culture Documents
COD Lecture 2 - Students
COD Lecture 2 - Students
ORGANIZATION &
DESIGN
SE – CIS Batch 2018
Spring 2020
Lecture Plan
• Unsigned Integer Representation
• Integer Arithmetic
• Addition / Subtraction
• Multiplication
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
3
Integer Types
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
4
Example
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
6
• Convert 12 to binary
… 26 25 24 23 22 21 20
… 164 32 16 8 4 2 1
0 0 0 1 1 0 0
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
7
… 256 128 64 32 16 8 4 2 1
0 1 0 0 1 0 1 0 0
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
8
1 0 0 0 0 0 0 0 0 0 1 0
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
9
0 2n -1
•n : number of bits
• 4-bits : 0 to 15
• 12-bits : 0 to 4095
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
10
Homework 1.1
1. Determine range of numbers that can be
expressed using following number of bits.
12 , 20 , 63 , 128 , 120
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
11
Representation
• Sign-Magnitude Representation
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
12
Negative Numbers
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
13
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
14
0 1 0 1 1 1 0 0
1 0 1 0 0 1 0 0
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
15
0 0000 -1 1111
1 0001 -2 1110
2 0010 -3 1101
3 0011 -4 1100
4 0100 -5 1011
5 0101 -6 1010
6 0110 -7 1001
7 0111 -8 1000
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
16
0 0000 -1 1111
1 0001 -2 1110
2 0010 -3 1101
3 0011 -4 1100
4 0100 -5 1011
5 0101 -6 1010
6 0110 -7 1001
7 0111 -8 1000
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
17
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
18
representation of Zero
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
19
•n : number of bits
• 4-bits : -8 to +7
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
20
Homework 1.2
1. With 2’s complement representation scheme,
determine range of numbers that can be
expressed using following number of bits.
a) 5-bits c) 8-bits
b) 16-bits d) 32-bits
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
21
Homework 1.2
2. Determine minimum number of bits needed to
represent following numbers using 2’s complement
representation scheme.
a) -12 d) 65
b) -32 e) 256
c) +32
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
22
Homework 1.2
3. Give 2’s complement representation of following
numbers using 8 bits & 12 bits.
a) 43 c) 200
b) -32 d) -75
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
23
1. Addition / Subtraction
2. Multiplication
3. Division
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
24
1. Addition / Subtraction
1. Express numbers using 2’s complement
representation scheme
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
25
Example
1) - 5 + 3 using 4 bits
Solution
-5 ?
5 0101
2’s complement 1011 = -5
3 0011
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
26
Example - Continued
-5 1011
+3 0 0 1 1
-2 1 1 1 0
Verification
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
27
Detecting Overflow
Ex. -5 + (- 4) using 4 bits
-5 1011
+ -4 1100
-9 10111
OVERFLOW
Positive result
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
28
same sign but the sign of result differs from the sign of
operands.
numbers
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
29
2. Multiplication
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
30
1011
x101
1011
00000
+ 101100
Final product
110111
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
31
Observation
• Binary multiplication can be implemented using
needed
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
32
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
33
Notion Used
C : 1-bit register
Q0 : bit 0 of register Q
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
34
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
35
1 0 1 0
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
36
0 inserted 0 1 0 1 0
at MSB discarded
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
37
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
38
C A Q Count Remarks
0 0000 1001 4 Initialization
0 1100 1001 4 Q0 = 1 so C,A A+M
0 0110 0100 3 Shift Right C,A,Q & Count -1
Count ≠ 0 so next cycle
0 0011 0010 3 Q0 = 0 so Shift Right C,A,Q
0 0011 0010 2 Count – 1 , Count ≠ 0 so next cycle
0 0001 1001 2 Q0 = 0 so Shift Right C,A,Q
0 0001 1001 1 Count – 1 , Count ≠ 0 so next cycle
0 1101 1001 1 Q0 = 1 so C,A A+M
0 0110 1100 0 Shift Right C,A,Q & Count -1
Count = 0 so end
39
C A Q Count Remarks
0 0000 1001 4 Initialization
0 1100 1001 4 Q0 = 1 so C,A A+M
0 0110 0100 3 Shift Right C,A,Q & Count -1
Count ≠ 0 so next cycle
0 0011 0010 3 Q0 = 0 so Shift Right C,A,Q
0 0011 0010 2 Count – 1 , Count ≠ 0 so next cycle
0 0001 1001 2 Q0 = 0 so Shift Right C,A,Q
0 0001 1001 1 Count – 1 , Count ≠ 0 so next cycle
0 1101 1001 1 Q0 = 1 so C,A A+M
0 0110 1100 0 Shift Right C,A,Q & Count -1
Count = 0 so end
Hardware Implementation
Recap
• Unsigned Integer Representation
• Integer Arithmetic
• Addition / Subtraction
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 1- Motivation & Need
42
Reading Assignment
• Go through all relevant sections from
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 1- Motivation & Need
43
Stay Home
Stay Safe
Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali