You are on page 1of 43

COMPUTER

ORGANIZATION &
DESIGN
SE – CIS Batch 2018
Spring 2020

Instructor : Anita Ali


CS-221 Computer Organization & Design Lecture 1- Motivation & Need
2

Lecture Plan
• Unsigned Integer Representation

• Signed 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

• Unsigned Integers  0 & positive integers

• Signed Integers  0 & both positive &


negative integers

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
4

Unsigned Integer Representation


• Binary number system

Example

•5  101 [ at least 3 bits are needed ]

• 8-bit representation of 5  00000101

• 16-bit representation of 5  00000000 00000101


Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
5

Decimal to Binary Conversion


• Previously you used to divide a decimal number

repeatedly till quotient becomes 0

• But it was time consuming

• Convert 2050 to binary

• How much time did you spend?

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
6

Decimal to Binary Conversion -


Quicker Method
• Use binary weight method instead

• 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

Decimal to Binary Conversion -


Quicker Method
• Convert 148 to binary

… 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

Decimal to Binary Conversion -


Quicker Method
• Seems to be confusing & time consuming

• Convert 2050 to binary

2048 1024 512 256 128 64 32 16 8 4 2 1

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

Range – Unsigned Integers

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.

5-bits, 8-bits, 16-bits, 32-bits

2. Determine minimum number of bits needed to


represent following numbers.

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

Signed Integer Representation


Signed Integer
• Includes both positive & negative numbers

Representation
• Sign-Magnitude Representation

• 1’s Complement Representation

• 2’s Complement Representation

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
12

2’s Complement Representation


Positive Numbers 

• using binary number system

Negative Numbers 

• using 2’s complement method

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
13

Taking 2’s Complement

• Leaving all least significant zeros as it is

• Leaving first 1 from least significant side as it is

• Invert all the remaining bits

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
14

2’s Complement – Example

0 1 0 1 1 1 0 0

scan from least significant bit

1 0 1 0 0 1 0 0

all bits are inverted remains unchanged

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
15

2’s Complement Representation – 4 bit


Integers
Number Representation Number Representation

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

2’s Complement – Some Observations

Number Representation Number Representation

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

2’s Complement – Some Observations

• For all positive numbers

•Most significant bit is 0

• For all negative numbers

•Most significant bit is 1

Note: +8 can not be represented using 4 bits

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
18

2’s Complement Representation

• Single representation for Zero

• Other signed representation methods have dual

representation of Zero

• Computers use 2’s complement method for

signed integer representation

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
19

Range – 2’s Complement Method


n-1
- (2 )  +(2n-1 -1)

•n : number of bits

• 4-bits : -8 to +7

• 7-bits : -64 to +63

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

Signed Integer Arithmetic

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

2. Preform straight binary addition

3. Discard End Carry

4. Result is in 2’s complement form

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

1110 2’s complement


- 0 0 1 0 = -2

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

End carry is discarded

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
28

Overflow Detection Rule


Overflow will happen in 2’s complement

addition/subtraction, when the operands have the

same sign but the sign of result differs from the sign of

operands.

Solution: Increase number of bits to represent

numbers
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
29

2. Multiplication

1. Unsigned Integer Multiplication

2. Signed Integer Multiplication

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
30

2.1 Unsigned Multiplication

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

check , shift and addition only


• i.e. Only Adder, Shift Logic & Control circuitry is

needed

Note: Multiplication of two n-bit numbers


needs at most 2n-bits to hold the product

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
32

Unsigned Multiplication Algorithm

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
33

Unsigned Multiplication Algorithm

Notion Used

C : 1-bit register

A, M & Q : n-bit registers

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

Unsigned Multiplication Algorithm


Shift Right (SHR)
Shift all bits one position towards right and insert 0
at most significant position
Example
1 0 1 0

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 2- Computer Arithmetic
35

Unsigned Multiplication Algorithm


Shift Right (SHR)
Shift all bits one position towards right and insert 0
at most significant position
Example
1 0 1 0

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

Unsigned Multiplication Algorithm


Shift Right (SHR)
Shift all bits one position towards right and insert 0
at most significant position
Example
1 0 1 0

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

Unsigned Multiplication Algorithm

Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
38

Example : 12 x 9 (4-bits) M = 1100

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

Example : 12 x 9 (4-bits) M = 1100

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

0110 1100 = product = 108 )10


CS-221 Computer Organization & Design Lecture 1- Motivation & Need
40

Hardware Implementation

Hardware Implementation of Unsigned Binary Multiplication


Department of Computer & Information Systems Engineering, NED University Instructor: Anita Ali
CS-221 Computer Organization & Design Lecture 1- Motivation & Need
41

Recap
• Unsigned Integer Representation

• Signed Integer Representation

• Integer Arithmetic

• Addition / Subtraction

• Unsigned Integer Multiplication

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

• Chapter 3 of text book

Computer Organization & Design (5th edition)

• Chapter 10 of reference book

Computer Organization & Architecture (10th ed)

Note: Be prepared for quiz in upcoming live session

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

You might also like