You are on page 1of 53

LOGIC DESIGN AND UPROCESSORS

EE-374 Dr. Nabeel Anwar Room 206, SMME.

Text books

Digital Logic and Computer Design by Morris Mano Digital Fundamentals by Floyd

Grading

Sessional: Two Quizzes/Assignments Final

30% 25% 45%

Digital System

Representing Information Electronically

Analog electronics deals with non-discrete values Digital electronics deals with discrete values

Digital Electronics
Digital Electronics represents information (0, 1) with

only two discrete values. Ideally no voltage (e.g., 0v) represents a 0 and full source voltage (e.g., 5v) represents a 1 Realistically low voltage (e.g., <1v) represents a 0 and high voltage (e.g., >4v) represents a 1 We achieve these discrete values by using switches. We use transistor switches, which operates at high speed, electronically, a small in size.

Analog versus Digital


Analog systems process time-varying signals that can take

on any value across a continuous range of voltages (in electrical/electronics systems).

Digital systems process time-varying signals that can take on

only one of two discrete values of voltages (in electrical/electronics systems).


Discrete values are called 1 and 0 (ON and OFF, HIGH and LOW,

TRUE and FALSE, etc.)

Benefits of Digital over Analog

Reproducibility Not effected by noise means quality Ease of design Data protection Programmable Speed Economy

Case Study of a Simple Logic Design: Seven Segment Display


L1 L 4 L2 L 5 L3 L 7 L 6

B3 0 0 0 0 0 0 0 0 1 1

B2 0 0 0 0 1 1 1 1 0 0

B1 0 0 1 1 0 0 1 1 0 0

B0 0 1 0 1 0 1 0 1 0 1

Val 0 1 2 3 4 5 6 7 8 9

Case Study (cont.)


L1 L 4 L2 L 5 L3 L 7 L 6
B3 0 0 0 0 0 0 0 0 1 1 B2 0 0 0 0 1 1 1 1 0 0 B1 0 0 1 1 0 0 1 1 0 0 B0 0 1 0 1 0 1 0 1 0 1 Val 0 1 2 3 4 5 6 7 8 9 L1 1 0 1 1 0 1 1 1 1 1 L2 0 0 1 1 1 1 1 0 1 1 L3 1 0 1 1 0 1 1 0 1 1 L4 1 0 0 0 1 1 1 0 1 1 L5 1 0 1 0 0 0 1 0 1 0 L6 1 1 1 1 1 0 0 1 1 1 L7 1 1 0 1 1 1 1 1 1 1

Digital Revolution
Digital systems started back in 1940s. Digital systems cover all areas of life: still pictures digital video digital audio telephone traffic lights Animation

Number Systems

13

Binary Numbers
Strings of binary digits (bits) One bit can store a number from 0 to 1 n bits can store numbers from 0 to 2n

14

Binary Powers of 2
Positional representation Each digit represents a power of 2
So 101 binary is 1 22 + 0 21 + 1 20 or 14 + 02 + 11=5

15

Converting Binary to Decimal


Easy, just multiply digit by power of 2 Just like a decimal number is represented Example follows

16

Binary Decimal Example


7 27 128 6 26 64 5 25 32 4 24 16 3 23 8 2 22 4 1 21 2 0 20 1

What is 10011100 in decimal?


1 0 0 1 1 1 0 0

128 + 0 + 0 + 16 + 8 + 4 + 0 + 0 = 156

17

Decimal to Binary
A little more work than binary to decimal Some examples 3 = 2 + 1 = 11 (thats 121 + 120) 5 = 4 + 1 = 101 (thats 122 + 021 + 120)

18

Algorithm Decimal to Binary


Find largest power-of-two smaller than decimal number Make the appropriate binary digit a 1 Subtract the power of 2 from decimal Do the same thing again

19

Decimal Binary Example


Convert 28 decimal to binary

32 is too large, so use 16 Binary 10000 Decimal 28 16 = 12 Next is 8 Binary 11000 Decimal 12 8 = 4 Next is 4 Binary 11100 Decimal 4 4 = 0
7 27 128 6 26 64 5 25 32 4 24 16 3 23 8 2 22 4 1 21 2 0 20 1

20

Hexadecimal
Strings of 0s and 1s too hard to write Use base-16 or hexadecimal 4 bits

Dec 0 1 2 3 4 5 6 7

Bin 0000 0001 0010 0011 0100 0101 0110 0111

Hex 0 1 2 3 4 5 6 7

Dec 8 9 10 11 12 13 14 15

Bin 1000 1001 1010 1011 1100 1101 1110 1111

Hex 8 9 ? ? ? ? ? ?

21

Hexadecimal
Letters to represent 10-15

Dec 0 1 2 3 4 5 6 7

Bin 0000 0001 0010 0011 0100 0101 0110 0111

Hex 0 1 2 3 4 5 6 7

Dec 8 9 10 11 12 13 14 15

Bin 1000 1001 1010 1011 1100 1101 1110 1111

Hex 8 9 a b c d e f

22

Hex to Binary
Convention write 0x before number Hex to Binary just convert digits

Bin 0000 0001 0010 0011 0100 0101

Hex 0 1 2 3 4 5 6 7 8 9 a b c d e f

0x2ac
0010 1010 1100

0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

0x2ac = 001010101100

No magic remember hex digit = 4 bits

23

Binary to Hex
Just convert groups of 4 bits

Bin 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Hex 0 1 2 3 4 5 6 7 8 9 a b c d e f

101001101111011 0101 0011 0111 1011


5 3 7 b

1010 1011 1100

101001101111011 = 0x537b

1101 1110 1111

24

Dec

Hex 0 1 2 3 4 5 6 7 8 9 a b c d e f

Hex to Decimal
Just multiply each hex digit by decimal value, and

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

add the results.

0x2ac 2 256
163 4096

+ 10 16 + 12 1 = 684
162 256 161 16 160 1

25

Decimal to Hex
1. 2. 3. 4.

Analogous to decimal binary. Find largest power-of-16 smaller than decimal number Divide by power-of-16. The integer result is hex digit. The remainder is new decimal number. Do the same thing again

26

Dec

Hex 0 1 2 3 4 5 6 7 8 9 a b c d e f

Decimal to Hex
684 684/256 = 2 684%256 = 172 172/16 = 10 = a
163 4096 162 256 161 16

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0x2__

0x2a_ 172%16 = 12 = c 0x2ac


160 1

27

Octal
Octal is base 8 Similar to hexadecimal Conversions Less convenient for use with 8-bit bytes

28

Arithmetic -- addition
Binary similar to decimal arithmetic

No carries

1 0 0 0 0 1 1

0 1

1 0 0 1

1 1 1 1

0 1 1 0

0 0 1 1

Carries

0 + 1 1

1 0 1

1 0 1

+ 1 1 0

1+1 is 2 (or 102), which results in a carry

29

Arithmetic -- subtraction

No borrows

0 1 1 0 0 0 0 1 1 0

0 1 0 1

1 1 0 0

1 1 1 1

0 0 1 1

Borrows

1 1 0

0 0 0

1 0 1

0 - 1 results in a borrow

30

Arithmetic -- multiplication
1 X 1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 1 1 1 0 1 0 1 1 1

Successive additions of multiplicand or zero, multiplied by 2 (102). Note that multiplication by 102 just shifts bits left.

31

Hexadecimal Arithmetic
Similar If youre doing by hand, easiest to convert each set of

digits to decimal and back Skill is not very useful

How we store numbers in Comp


A number can be signed or unsigned. An unsigned integer is either positive or zero. Consider a single digit decimal number: in a single decimal digit, you can write a number between 0 and 9. In two decimal digits, you can write a number between 0 and 99, and so on. Since nine is equivalent to 10 1 - 1, 99 is equivalent to 10 2 - 1, etc The generalized limit is 0 and 10 n - 1

How we store numbers in Comp


For a binary number 0 and 2 n - 1 For one byte (8 bits) the maximum UNSIGNED number can goes to 0 to 2 8 - 1 = 0 to 255 What about SIGNED number?

One common method is to reserve MSB as sign indication.

How we store numbers in Comp


The range of the sign number is -2n - 1 to 2 n-1 - 1 For one byte (8 bits) the maximum SIGNED number can goes to -128 to 127

Instead of storing the - sign with the number computer simply assign one bit as a sign bit Then how computer performs arithmetic?

Negative number representation


Property Two's complement representation allows the use of binary arithmetic operations on signed integers, yielding the correct 2's complement results. Positive Numbers: Positive 2's complement numbers are represented as the simple binary. Negative Numbers: Negative 2's complement numbers are represented as the binary number that when added to a positive number of the same magnitude equals zero.

Negative number representation


Integer Signed 5 4 3 2 1 0 -1 -2 -3 -4 -5 Unsigned 5 4 3 2 1 0 255 254 253 252 251 2's Complement

0000 0101 0000 0100 0000 0011 0000 0010 0000 0001 0000 0000 1111 1111 1111 1110 1111 1101 1111 1100 1111 1011

Subtraction using addition


Conventional addition (using carry) is easily

implemented in digital computers.


However; subtraction by borrowing is difficult and

inefficient for digital computers.


Much more efficient to implement subtraction

using ADDITION OF the COMPLEMENTS of numbers.

Complements of numbers
(r-1 )s Complement
Given a number N in base r having n digits, complement of N is defined as (rn - 1) - N For decimal numbers the base or r = 10 and r- 1= 9, so the 9s complement of N is (10n-1)-N 99999. - N the (r- 1)s

9 Digit n-1

9 Next digit

9 Next digit

9 First digit

Digit n

9s complement Examples
9 9 4 5 9 6 3 9 7 2 9 0 9 9 0 9

Example: Find the 9s complement of 546700 and 12389 The 9s complement of 546700 is 999999 - 546700= 453299

5 4

9 2 7

9 3 6

9 8 1

9 9 0

and the 9s complement of 12389 is 99999- 12389 = 87610.

1 8

1s complement
For binary numbers, r = 2 and r 1 = 1, r-1s complement is the ls complement. The ls complement of N is (2n - 1) - N.

Bit n-1

Bit n-2

Bit 1

Bit 0

1 Digit n-1

1 Next digit

1 Next digit

1 First digit

Digit n

ls complement

Find r-1 complement for binary number N with four binary digits. r-1 complement for binary means 2-1 complement or 1s complement. n = 4, we have 24 = (10000)2 and 24 - 1 = (1111)2. The ls complement of N is (24 - 1) - N. = (1111) - N

ls complement

1 0 1

1 1 0

1 1 0

1 0 1

1 0 1

1 1 0

The complement 1s of 1011001 is 0100110

1 0

1 0 1

1 0 1

1 1 0

1 1 0

1 1 0

1 1 0

The 1s complement of 0001111 is 1110000

0 1

rs Complement
Given a number N in base r having n digits, the rs complement of N is defined as rn - N. For decimal numbers the base or r = 10,
1 0 0 Digit n-1 0 Next digit 0 Next digit 0 First digit

so the 10s complement of N is 10n-N. 100000. - N

Digit n

10s complement Examples


Find the 10s complement of 546700 and 12389 The 10s complement of 546700 is 1000000 - 546700= 453300 and the 10s complement of 12389 is 100000 - 12389 = 87611. Notice that it is the same as 9s complement + 1.

0 5 4

0 4 5

0 6 3

0 7 3

0 0 0

0 0 0

0 1 8

0 2 7

0 3 6

0 8 1

0 9 1

2s complement
For binary numbers, r = 2, rs complement is the 2s complement. The 2s complement of N is 2n - N.

0 Digit n-1

0 Next digit

0 Next digit

0 First digit

Digit n

2s complement Example
1 0 1 0 0 0 1 0 1 0 0 1 0 0 0 1 0 0 1 0 1 1

The 2s complement of 1011001 is 0100111

0 0 1

0 0 1

0 0 1

0 1 0

0 1 0

0 1 0

0 1 1

The 2s complement of 0001111 is 1110001

Fast Methods for 2s Complement

Method 1:
The 2s complement of binary number is obtained by adding 1 to the ls complement value. Example: 1s complement of 101100 is 010011 (invert the 0s and 1s) 2s complement of 101100 is 010011 + 1 = 010100

Fast Methods for 2s Complement


Method 2:
The 2s complement can be formed by leaving all least significant 0s and the first 1 unchanged, and then replacing ls by 0s and 0s by ls in all other higher significant bits. Example: The 2s complement of 1101100 is 0010100 Leave the two low-order 0s and the first 1 unchanged, and then replacing 1s by 0s and 0s by 1s in the four most significant bits.

Examples
Finding the 2s complement of (01100101)2 Method 1 Simply complement each bit and then add 1 to the result. (01100101)2 [N] = 2s complement = 1s complement (10011010)2 +1 =(10011011)2 Method 2 Starting with the least significant bit, copy all the bits up to and including the first 1 bit and then complement the remaining bits. N =01100101 [N] = 1 0 0 1 1 0 1 1

Subtraction of Unsigned Numbers using rs complement Subtract N from M :


rs complement add M to ( rn N ) :

MN N (rn N )

Sum = M + ( r n N)

take rs complement (If M N, the negative sign

will produce an end carry rn we need to take the rs complement again.)

Subtraction of Unsigned Numbers using rs complement


(1) if M N, ignore the carry without taking complement of

sum. (2) if M < N, take the rs complement of sum and place negative sign in front of sum. The answer is negative.

Example 1 (Decimal unsigned numbers), perform the subtraction 72532 - 13250 = 59282. M > N : Case 1 Do not take complement of sum and discard carry The 10s complement of 13250 is 86750. Therefore: M= 72532 10s complement of N =+86750 Sum= 159282 Discard end carry 105= - 100000 Answer = 59282 no complement

Example 2; Now consider an example with M <N. The subtraction 13250 - 72532 produces negative 59282. Using the procedure with complements, we have M = 13250 10s complement of N = +27468 Sum = 40718 Take 10s complement of Sum = 100000 -40718 The number is : 59282

Place negative sign in front of the number: -59282

You might also like