15
BIL 201 BIL 201 Mantıksal Mantıksal Tasarım Tasarım (Logical Design) (Logical Design) Güz Güz 2011 2011 Güz Güz 2011 2011 Bilgisayar Mühendisligi Bölümü Hacettepe Üniversitesi General Information General Information Web page: To be announced later.. Instructors: Ahmet Burak Can, Aykut Erdem {abc,aykut}@cs.hacettepe.edu.tr Office Rooms: 113/205 Textbook: Mano and Ciletti, Digital Design Pearson, 4 th Edition Other references: Other references: Yarımagan, Sayısal Devrelerde Mantıksal Tasarım, Bıçaklar Kitabevi Schedule: Wednesday 9:15 – 12:00 Message group: piazza.com 2 Acknowledgements Acknowledgements Course slides adapted from - Textbook slides - Slides of Nese Yalabik for CENG 232 – Digital Design course (METU) 3 Course objectives Course objectives To learn how to design, analyze, and evaluate digital (i.e. boolean) circuits To understand the workings of the computer - Hardware components - How to design these basic components - How to design these basic components - How to design digital circuits other than computers 4

Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

  • Upload
    doanthu

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

BIL 201 BIL 201 MantıksalMantıksal TasarımTasarım(Logical Design) (Logical Design)

GüzGüz 20112011GüzGüz 20112011Bilgisayar Mühendisligi Bölümü

Hacettepe Üniversitesi

General InformationGeneral Information• Web page:

To be announced later..

• Instructors:Ahmet Burak Can,

Aykut Erdem{abc,aykut}@cs.hacettepe.edu.trOffice Rooms: 113/205

• Textbook:Mano and Ciletti, Digital Design Pearson, 4th Edition

• Other references:• Other references:Yarımagan, Sayısal DevrelerdeMantıksal Tasarım, Bıçaklar Kitabevi

• Schedule: Wednesday 9:15 – 12:00

• Message group: piazza.com

2

AcknowledgementsAcknowledgements

• Course slides adapted from- Textbook slides

- Slides of Nese Yalabik for CENG 232 – Digital Design course (METU)

3

Course objectivesCourse objectives

• To learn how to design, analyze, and evaluate digital (i.e. boolean) circuits

• To understand the workings of the computer- Hardware components - How to design these basic components- How to design these basic components- How to design digital circuits other than computers

4

Page 2: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

OutlineOutline

• Historial overview• Digital systems (sayısal sistemler)• Binary numbers (ikili sayılar)• Octal and Hexadecimal numbers (sekizli ve onaltılı

sayılar)sayılar)• Complements (tümler)• Addition and subtraction• Binary codes (ikili kodlar)• Binary storage and registers (ikili saklama ve yazmaçlar)• Binary logic (ikili mantık)• Logic gates (mantık kapıları)

5

Historical OverviewHistorical Overview

• The Mechanical Age- Abacus (500 B.C.)

- Antikythera mechanism (150-100 B.C.)

- Jacquard loom (Joseph Marie Jacquard, 1801)

- The Analytical Engine (Charles Babbage UK, 1837) - The Analytical Engine (Charles Babbage UK, 1837)

- ...

6

Historical OverviewHistorical Overview

• The Electrical Age- Z3 (Konrad Zuse, Germany, 1941) (Turing-complete)

- ABC (Atanasoff and Berry, USA, 1942) (digital)

- Colossus Mark 1 (UK,1944)

- ENIAC (Mauchly and Eckert, USA, 1946) - ENIAC (Mauchly and Eckert, USA, 1946)

- EDVAC (von Neuman, USA, 1951), N

7

An Historical OverviewAn Historical Overview

• The Microprocessor Age - Intel 4004 (1971) (4-bit)

- TMS 1000 (1974) (4-bit)

- N

- Intel Xeon (1998-present) (32/64-bit)

8

Page 3: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

Moore’s LawMoore’s Law

Source: Intel Corporation9

Digital systemsDigital systems

• Digital computers, smart phones, digital cameras, etc.

• A digital system has the ability to represent and manipulate discrete elements of information

Finite set of information, e.g. 10 decimal digits, the 26 letters

of the English alphabet, the 64 squares of a chessboardof the English alphabet, the 64 squares of a chessboard

• Digital systems manipulate information as 1s and 0s

- binary codes (the mapping of symbols to binary value)

- a binary digit is called a bit, has two values 0 and 1 r)(represented by electrical signals that can have one of

two voltage levels)

10

• Digital vs. analog waveforms

+5

1 0 1

+5

Digital systemsDigital systems

Analog: • values vary over a broad range

continuously

Digital: • only assumes discrete values

V

–5

1 0 1

T ime V

–5

T ime

11

DigitalDigital systemssystems

• Add two numbers in an analog circuitryDesign a circuit that will perform Z=X+Y

3

47 volts

volts

voltsAnalog Adder

• Add two numbers in digital circuitry

Digital(Binary)Adder

0011

0100

0111

0,1 can be around

0-5 volts

12

Page 4: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

Digital sDigital systemsystems

• Digital binary system- Two discrete values:

• yes, on, 5 volts, current flowing, “1” in practice varies between 4 and 5.5 for outputs and a wider

range for inputsrange for inputs

• no, off, 0 volts, no current flowing, “0”between 0 and 1

• Advantages of binary systems- Rigorous mathematical foundation based on logic

- It’s easy to implement

- Less error prone than analog

13

Decimal numbersDecimal numbers

• We humans use decimal system of numbers• A weighted position number system

7394 = 7x103 + 3x102 + 9x101 + 4x100

• The decimal system is also called base (radix) 10 systemsystem

• Purely a human invention“It is India that gave us the ingenious method of expressing all numbers by means of ten

symbols, each symbol receiving a value of position as well as an absolute value; a profound and important idea which appears so simple to us now that we ignore its true merit.” – Laplace

14

Number systemsNumber systems

• In general, a number is represented in a base-rsystem as:N = an r

n + an-1 r n-1 + 3 + a1 r

1 + a0 r 0 + a-1 r

-1 + 3 + a-(m-1) r

–m+1 + a-mr -m

each coefficient aj ranges between 0 to r-1

15

• r = 2 is called the binary system

• The coefficients (digits) are 0 and 1.e.g., 26.75 = 11010.11

= 1x24 + 1x23 + 0x22 + 1x21 +0x20 + 1x2-1 + 1x2-2

Binary numbersBinary numbers

= 1x2 + 1x2 + 0x2 + 1x2 +0x2 + 1x2 + 1x2

• Least Significant Bit (LSB) - The bit on the rightmost position

• Most Significant Bit (MSB)- The bit on the leftmost position

• Bit – a single binary digit

• Nibble – a group of four bits

• Byte – a group of eight bits

• Word – 8, 16, 32, or 64 bits

(depends on processor)

16

Page 5: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

Decimal numbers to Binary numbersDecimal numbers to Binary numbers

• Divide the number and all successive quotients by 2 and keep track of the remainders.

e.g., (41)10 = (101001)2

If the number includes a radix point, one needs to

separate the number into an integer and a fraction part

17

Decimal Decimal fractional numbers fractional numbers to bto binaryinary

• Use multiplication (instead of division)

e.g., (0.6875)10 = (0.1011)2

Conversion may not be exact, i.e. a repeated fraction

18

Decimal fractional numbers to binaryDecimal fractional numbers to binary

Convert 13.2 to binary

Integer Fraction13 / 2 = 6 R 1 LSB .2 x 2 = 0.4 MSB6 / 2 = 3 R 0 .4 x 2 = 0.83 / 2 = 1 R 1 .8 x 2 = 1.63 / 2 = 1 R 1 .8 x 2 = 1.61 / 2 = 0 R 1 MSB .6 x 2 = 1.2

.2 x 2 = 0.4 LSB repeating

Result is 1101.00110011N...

To check correctness, you can always convert back

the result to decimal

19

• Some simplifications over binary system

• r = 8 is called the octal system- 8 digits: 0, 1, 2, N, 6, 7

e.g., (127.4)8 = 1x82 + 2x81 + 7x80 + 4x8-1 = (87.5)10

• r = 16 is called the hexadecimal system

Octal and Hexadecimal SystemsOctal and Hexadecimal Systems

• r = 16 is called the hexadecimal system- 16 digits: 0, 1, N, 9, A(10), B(11), C(12), D(13), E (14), F (15)

e.g., (B65F)16 = 11x163+6x162 + 5x161 + 15x160 = (46.687)10

The number represented in these number systems can

be easily converted to/from binary

20

Page 6: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

Binary numbersBinary numbers

©2007 by Prentice Hall, Inc.

A Pearson Company21

Octal and Hexadecimal Octal and Hexadecimal SystemsSystems

• Conversion to/from decimal follows the same strategy with a radix of 8 or 16 instead of 2

• To convert from binary:- Starting at radix point, go left/right and group bits into - Starting at radix point, go left/right and group bits into

groups of 3 or 4 bits / group

- Convert each bit group into equivalent octal or hex digit

• To convert to binary expand each octal / hex digit into equivalent 3 or 4 bit binary value.

22

Octal and Hexadecimal Octal and Hexadecimal SystemsSystems

• Conversion to/from binary

0100111010111010.01100010101100101000

4 E B A . 6 2 B 2 8

0100111010111010.01100010101100101000

4 7 2 7 2 . 3 0 5 3 1 2

23

Representing Representing unsignedunsigned numbersnumbers

• All the n bits are assumed to represent onlypositive numbers

• For integers, between 0 – (2n-1) (inclusive)

e.g. An 8 bit word can represent unsigned numberse.g. An 8 bit word can represent unsigned numbers

{00000000,00000001,33,11111111}

i.e. 0,1,2,3,(28-1) =255 in decimal

24

Page 7: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

Representing Representing signedsigned numbersnumbers

• Positive number representation same in most systems- Standard positional binary notation

- MSB is the sign bit, 0 = plus, 1 = minus

- Nearly half are positive, half are negative

• Major differences are in how negative numbers are represented

• Three major schemes:- Sign-magnitude

- 1’s complement

- 2’s complement 25

• Assume a 4-bit machine word

• High order bit is the sign 0 = positive (or zero), 1 = negative

• Three low order bits is the magnitude: 0 (000) through 7 (111)

SignSign--Magnitude Magnitude representationrepresentation

+0+1

+2

+3

+4

00010000

0010

0011

01001100

1101

11101111

-7

-6

-5

-4• Number range for n bits = ±2n-1 - 1

• Two representations for 0

• The major disadvantage is that we need separate circuits to both add and subtract

• Number magnitudes need to be compared to get the right result

+4

+5

+6

+7

0100

0101

01100111

1000

1100

10011010

1011

-4

-3

-2

-1-0

0 100 = +4

1 100 = - 4

26

Representing Representing --NN

• How to represent –N?

• A - B is equivalent to A + (-B)

• We really are working in a closed, modulo number system, 0 to 2r-1 valuesnumber system, 0 to 2 values

• Therefore for r bits, 2r ≡ 0

• If -N ≡ 0 - N then -N ≡ 2r - N

The 2’s complement representation for

-N

27

+0+1

+2

+3

00010000

0010

00111101

11101111

-1

-2

3

2’s complement 2’s complement rrepresentationepresentation

• Only one representation for 0

• One more negative number than positive number

+4

+5

+6

+7

0100

0101

01100111

1000

1100

10011010

1011

-4

-5

-6

-7-8

• Generation of the 2’s complement as 2r - N implies r+1 bits available in system

28

Page 8: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

2’s complement representation2’s complement representation

• Twos complement of 7 24 = 10000subtract 7 = _0111

1001 = repr. of -7

• Twos complement of -7 24 = 10000subtract -7 = _1001subtract -7 = _1001

0111 = repr. of 7

• Twos complement = Bitwise complement +10111 → 1000 + 1 → 1001 (representation of -7)

1001 → 0110 + 1 → 0111 (representation of 7)

29

1’s complement 1’s complement rrepresentationepresentation

• N is positive number, then N* is its negative 1's complement

N* = (2n - 1) – N

e.g., 1's complement of 7

24 = 10000

-1 = 00001

1111e.g., 1's complement of 7

• Simply compute bitwise complement0111 => 1000

1111

-7 = 0111

1000= -7 in 1's comp.

30

+0+1

+2

+3

+4

00010000

0010

0011

01001100

1101

11101111

-0

-1

-2

-3

like 2's comp except shiftedone position counter-clockwise

Ones Ones complement complement representationrepresentation

• Subtraction implemented by addition & 1's complement

+4

+5

+6

+7

0100

0101

01100111

1000

1100

10011010

1011

-3

-4

-5

-6-7

• Still two representations of 0! causes some problems

• Some complexities in addition

31

4

+ 3

7

0100

0011

0111

-4

+ (-3)

-7

1100

1011

1111

Result sign bit is thesame as the operands'sign

Addition and Addition and Subtraction Subtraction –– SignSign--MagnitudeMagnitude

7 0111 -7 1111

4

- 3

1

0100

1011

0001

-4

+ 3

-1

1100

0011

1001

When signs differ,operation is subtract,sign of result dependson sign of number withthe larger magnitude

32

Page 9: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

4

+ 3

7

0100

0011

0111

-4

+ (-3)

-7

1011

1100

10111

1End around carry

Addition and Addition and Subtraction Subtraction ––1’s Complement1’s Complement

1000

4

- 3

1

0100

1100

10000

1

0001

-4

+ 3

-1

1011

0011

1110

End around carry

33

Addition and Addition and Subtraction Subtraction ––1’s Complement1’s Complement

• Why does end-around carry work?

Its equivalent to subtracting 2n and adding 1

M - N = M + N* = M + (2n - 1 - N) = (M - N) + 2n - 1(M > N)(M > N)

-M + (-N) = (2n - M - 1) + (2n - N - 1)

= 2n + [2n - 1 - (M + N)] - 1M + N < 2n-1

after end around carry:= 2n - 1 - (M + N)

The correct form for representing -(M + N) in 1's complement!34

Addition and Addition and Subtraction Subtraction ––2’s complement2’s complement

4

+ 3

7

0100

0011

0111

-4

+ (-3)

-7

1100

1101

11001If carry-in to sign =carry-out then ignore

4

- 3

1

0100

1101

10001

-4

+ 3

-1

1100

0011

1111

carry-out then ignorecarry

if carry-in differs fromcarry-out then overflow

Simpler addition scheme makes twos complement the most commonchoice for integer number systems within digital systems

35

Addition and Addition and Subtraction Subtraction ––2’s complement2’s complement

• Why can the carry-out be ignored?

-M + N when N > M:

M* + N = (2n - M) + N = 2n + (N - M)

Ignoring carry-out is just like subtracting 2nIgnoring carry-out is just like subtracting 2n

-M + -N where N + M < or = 2n-1

-M + (-N) = M* + N* = (2n - M) + (2n - N)

= 2n - (M + N) + 2n

After ignoring the carry, this is just the right two’s compliment representation for -(M + N)!

36

Page 10: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

Addition and Subtraction Addition and Subtraction --Overflow Overflow ConditionsConditions

0000

00011110

1111

+0

+1

-3

-2

-1

0000

00011110

1111

+0

+1

-3

-2

-1

• Add two positive numbers to get a negative number or two negative numbers to get a positive number

5 + 3 = -8

0001

0010

0011

1000

0101

0110

0100

1001

1010

1011

1100

1101

0111

1110+2

+3

+4

+5

+6

+7-8

-7

-6

-5

-4

-3

-7 - 2 = +7

0001

0010

0011

1000

0101

0110

0100

1001

1010

1011

1100

1101

0111

1110+2

+3

+4

+5

+6

+7-8

-7

-6

-5

-4

-3

37

Overflow ConditionsOverflow Conditions

5

3

-8

0 1 0 1

0 0 1 1

1 0 0 0

-7

-2

7

1 0 0 1

1 1 0 0

1 0 1 1 1Overflow Overflow

5

2

7

0 1 0 1

0 0 1 0

0 1 1 1

-3

-5

-8

1 1 0 1

1 0 1 1

1 1 0 0 0

No overflow No overflow

Overflow when carry in to sign does not equal carry out

38

Weighted and Weighted and unweightedunweightedcodescodes

• Most numeric number representations are in a class known as weighted codes where

val = bi⋅w

i

r−1

• Binary integers and fractions are special case where weights are powers of 2

• Unweighted codes are codes that cannot be assigned a weight value for each bit

val = bi⋅w

i

i=0

39

Binary Coded Binary Coded Decimal (BCD)Decimal (BCD)

• Four bits are used to represent each decimal digit- In each 4-bit group, 6 values are not used

- Many possible codes, natural BCD (equivalent binary digits) most commondigits) most common

- BCD is not as efficient as binary

• BCD is easy to convert to/from decimal (it really is decimal with different symbols)

• BCD add/subtract circuits are complex

40

Page 11: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

Binary codesBinary codes

Unweighted code

Weighted codes

The 8421 or natural BCD code is the most common BCD code

in use41

BCD AdditionBCD Addition

Case 1: Case 2:0001 1

0101 5

(0) 0110 (0) 6

0110 6

0101 5

(0) 1011 (1) 1

Case 3: 1000 8

1001 9

(1) 0001 (1) 7

WRONG!

Note that for cases 2 and 3,

adding a factor of 6 (0110)

gives us the correct result.

42

BCD BCD AdditionAddition

• BCD addition is therefore performed as follows- 1) Add the two BCD digits together using normal

binary addition

- 2) Check if correction is needed• a) 4-bit sum is in range of 1010 to 1111• a) 4-bit sum is in range of 1010 to 1111

• b) carry out of MSB = 1

- 3) If correction is required, add 0110 to 4-bit sum to get the correct result; BCD carry out = 1

43

Negative BCD NumbersNegative BCD Numbers

• Similar to binary negative number representation except r = 10.- BCD sign-magnitude

• MSD (sign digit options)• MSD (sign digit options)o MSD = 0 (positive); not equal to 0 = negative

o MSD range of 0-4 positive; 5-9 negative

- BCD 10’s complement• -N ≡ 10r - N; 9’s complement + 1

- BCD 9’s complement• invert each BCD digit

(0→9, 1 → 8, 2 → 7,3 → 6, N7 → 2, 8 → 1, 9 → 0)44

Page 12: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

Negative BCD NumbersNegative BCD Numbers

• 84-2-1 and XS3 codes allow for easy digit inversion.

• XS3 code is also easy to implement- Addition is like binary- Addition is like binary

- Correction factor is -3 or +3

45

Gray Gray codescodes

• Grey codes are minimum change codes- From one numeric

representation to the next, only one bit changesonly one bit changes

- Primary use is in numeric input encoding apps. where we expect non-random input values changes (i.e. value n to either n-1 or n+1)

• Milling machine table position• Rotary shaft position

46

Alphanumeric RepresentationAlphanumeric Representation

• Binary codes used to represent alphabetic and numeric characters

• Two most common are:- ASCII, 7 bit code, 128 symbols- EBCDIC, 8 bit code, 256 - EBCDIC, 8 bit code, 256

symbols

• Problems can arise when comparing symbol values (collation)- Comparing ‘A’ to ‘a’ in ASCII

system yields different results in in EBCDIC system.

47

ASCIIASCII

48

Page 13: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

Parity BitParity Bit

• ASCII code may have an extra bit appended to detect data transmission errors- P = 0 if the number of 1s in the character is even, else

P = 1 (even parity)

- P = 0 if the number of 1s in the character is odd, else - P = 0 if the number of 1s in the character is odd, else P = 1 (odd parity)

• If any single bit changes, parity will be wrong at receive end

Even parity Odd parity

ASCII A = 1000001 01000001 11000001ASCII T = 1010100 11010100 01010100

49

Other Other information information representationrepresentation

• ALL information must be encoded before we can design circuits to process it

• You can assign any code to any information- e.g., 00 - north, 01 - east, 11 - south, 10 - west- e.g., 00 - north, 01 - east, 11 - south, 10 - west

• If the information goes somewhere else, the user has to have access to your definition

• Standards are best if available- Already published and easily available

- Allows your system to work with many others

50

Binary Storage and RegistersBinary Storage and Registers

• A binary cell is a device that possesses two stable states - Can store a single bit (0 or 1) of information

• A register is a group of binary cells• A register is a group of binary cells- A register with n cells can store n-bit of information

51

Transfer of information among Transfer of information among registersregisters

• Transfering binary information from one set of registers into another (register transfer)- May be direct, or may involve - May be direct, or may involve

passing through data-processing circuits

52

Page 14: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

Binary information processingBinary information processing

• Binary variables are manipulated by means of digital logic circuits- e.g., an adder circuit

53

Binary logicBinary logic

• Binary logic deals with binary variables and a set of logical operations.- Binary variables can take only two values, 0 and 1.

• 3 basic logical operations: AND, OR and NOT• 3 basic logical operations: AND, OR and NOTFor x and y binary variables, the three logical operations are shown as:

- AND operation (�) x�y

- OR operation (+) x+y

- NOT operation ’ x’

54

Binary logicBinary logic

55

Logic gatesLogic gates

• Logic gates are electronic circuit which implement basic logic operations. - Electrical signals (voltages, currents,

etc.) are treated as 0 or 1.

• Logic 0 may be defined as 0 volts • Logic 0 may be defined as 0 volts and logic 1 may be defined as 5 volts.

• But usually the range of voltages are used- 0: 0V to 1V - 1: 2V to 3V

Having a range of allowable voltage

values makes the binary logic less prone to

errors.56

Page 15: Acknowledgements Course objectives - Hacettepeaykut/classes/fall2012/bbm231/... · Convert 13.2 to binary ... • r = 16 is called the hexadecimal system Octal and Hexadecimal Systems

Logic gatesLogic gates

57

Logic gatesLogic gates

58