comparch lec01 number system and gates

60
Lecture 1. Number System and Logic Gates COSC3330 Computer Architecture Instructor: We idong Shi (Larry), PhD Computer Science Department University of Houston

Upload: trung-nguyen

Post on 03-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 1/60

Lecture 1. Number System and Logic Gates

COSC3330 Computer Architecture

Instructor: Weidong Shi (Larry), PhDComputer Science Department

University of Houston

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 2/60

Today

• Numbers

• Logic gates

2

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 3/60

1000 Apples in 10 Boxes

3

• How to arrange 1000apples in 10 boxes sothat any number ofapples can be pickedin terms of boxes?

117 Apples

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 4/60

A Computer System

• What are there inside a computer?

4

CPU

NorthBridge

SouthBridge

MainMemory(DDR2)

FSB(Front-Side Bus)

DMI(Direct Media I/F)

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 5/60

Bottom Layer of a Computer

• Each component inside a computer is basicallymade based on analog and digital circuits

Analog• Continuous signal

Digital• Only knows 1 and 0

5

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 6/60

What Do You Mean by 0 or 1 in Digital Circuit?

• In fact, everything in this world is analogFor example, sound, light, electric signals are all analog since theyare continuous in time

Actually, digital circuit is a special case of analog circuit

• Power supply provides power to the computer system• Power supply has several outlets (such as 3.3V, 5V, and 12V)

6

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 7/60

What Do You Mean by 0 or 1 in Digital Circuit?

7

Digital circuit treats a signal above a certain level as “1” and asignal below a certain level as “0”

Different components in a computer have different voltagerequirements ( Voltage requirements change as the technologyadvances)

• CPU (Core 2 Duo): 1.325 V• Chipsets: 1.45 V• Peripheral devices: 3.3V, 1.5V

0V

1.325V

time

“1”

“0”

Not determined

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 8/60

Logic Levels

• Define a range of voltages to represent 1 and 0• Define different ranges for outputs and inputs toallow for noise in the system

Noise is anything that degrades the signal

• For example, a gate (driver) could output a 5 voltsignal but, because of losses in the wire and othernoise, the signal could arrive at the receiver with adegraded value, for example, 4.5 volts

8

Driver Receiver Noise

5 V 4.5 V

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 9/60

Logic Levels

9

Driver Receiver

ForbiddenZone

NM L

NM H

Input CharacteristicsOutput Characteristics

V O H

V DD

V O

L

GND

V IH

V IL

Logic HighInput Range

Logic LowInput Range

Logic HighOutput Range

Logic LowOutput Range

Noise Margin

NMH = V OH – V IHNML = V IL – V OL

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 10/60

Digital vs. Analog

10

Digital Analog music

video

wireless signal

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 11/60

DSP – Digital Signal Processing

a bit loudAnalog Computer

Digital Computer

ADC

DSP

DAC OUTPUT

1010 1001

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 12/60

Number Systems

• Analog information (video, sound etc) isconverted to a digital format for processing• Computer processes information in digital• Since digital knows “1” and “0”, we use different

number systems in computerBinary and Hexadecimal numbers

12

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 13/60

Number Systems - Decimal

• Decimal numbersMost natural to human because we have ten fingers(?) and/or because we are used to it (?)Each column of a decimal number has 10x the weight

of the previous column• Decimal number has 10 as its base

ex) 5374 10 = 5 x 10 3 + 3 x 10 2 + 7 x 10 1 + 4 x 10 0

N-digit number represents one of 10 N possibilities

ex) 3-digit number represents one of 1000 possibilities: 0 ~ 999

13

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 14/60

Number Systems - Binary

• Binary numbersBit represents one of 2 values: 0 or 1Each column of a binary number has 2x the weight ofthe previous column

• Binary number has 2 as its baseex) 10110 2 = 1 x 2 4 + 0 x 2 3 + 1 x 2 2 + 1 x 2 1 + 0 x 2 0 = 22 10

N-bit binary number represents one of 2 N possibilitiesex) 3-bit binary number represents one of 8 possibilities: 0 ~ 7

14

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 15/60

Counting Binary Numbers

• 0• 1• 2

• 3• 4• 5• 6• 7• 8…

01

10

11

100

101

110

111

1000

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 16/60

Power of 2

• 20 =• 21 =• 22 =

• 23

=• 24 =• 25 =• 26 =• 27 =

16

• 28

=• 29 =• 210 =• 211 =• 212 =• 213 =• 214 =• 215 =

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 17/60

Power of 2

• 20 = 1• 21 = 2• 22 = 4

• 23

= 8• 24 = 16• 25 = 32• 26 = 64• 27 = 128

* Handy to memorize up to 2 9

17

• 28

= 256• 29 = 512• 210 = 1024• 211 = 2048• 212 = 4096• 213 = 8192• 214 = 16384• 215 = 32768

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 18/60

Number Systems - Hexadecimal

• Hexadecimal numbersWriting long binary numbers is tedious and error-proneWe group 4 bits to form a hexadecimal (hex)

• A hex represents one of 16 values0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F

Each column of a hex number has 16x the weight of theprevious column

• Hexadecimal number has 16 as its base

ex) 2ED 16 = 2 x 16 2 + E (14) x 16 1 + D (13) x 16 0 = 749 10

N-hexadigit number represents one of 16 N possibilitiesex) 2-hexadigit number represents one of 16 2 possibilities: 0 ~ 255

18

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 19/60

Number Systems

19

Hex Number Decimal Equivalent Binary Equivalent

0 0 00001 1 0001

2 2 0010

3 3 0011

4 4 0100

5 5 0101

6 6 0110

7 7 0111

8 8 1000

9 9 1001

A 10 1010

B 11 1011

C 12 1100

D 13 1101

E 14 1110

F 15 1111

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 20/60

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 21/60

Number Conversions

75237

18

9421

222

22

02

1

101001

Convert 75 10 to binary number

7510

= 100 10112

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 22/60

Bits, Bytes, Nibbles

• Bits (b)

• Bytes & NibblesByte (B) = 8 bits

• Used everyday

Nibble (N) = 4 bits• Not commonly used

22

10010110nibble

byte

CEBF9AD7least

significantbyte

mostsignificant

byte

10010110leastsignificant

bit

mostsignificant

bit

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 23/60

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 24/60

Quick Checks

• 222 =?2 2 × 2 20 = 4 Mega

• How many values can a 32-bit variable

represent?2 2 × 2 30 = 4 Giga

• Suppose that you have 2GB main memory in

your computer. How many bits you need toaddress (cover) 2GB?2 1 × 2 30 = 2 GB, so 31 bits

24

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 25/60

Addition

25

37345168+

8902

carries11

10110011+1110

11 carries

• Decimal

• Binary

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 26/60

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 27/60

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 28/60

Signed Binary Numbers

• How does the computer represent positive andnegative integer numbers?• There are 2 ways

Sign/Magnitude Numbers

Two’s Complement Numbers

28

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 29/60

Sign/Magnitude Numbers

• 1 sign bit, N -1 magnitude bits• Sign bit is the most significant (left-most) bitNegative number: sign bit = 1Positive number: sign bit = 0

• Example: 4 -bit representations of ± 5:+5 = 0101 2 - 5 = 1101 2

29

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 30/60

Sign/Magnitude Numbers

SignedDecimal

Sign/MagnitudeNumbers

UnsignedDecimal

0 000 0

1 001 1

2 010 2

3 011 3

-0 100 4

-1 101 5

-2 110 6

-3 111 7

• Range of anN

-bitsign/magnitudenumber:[- (2 N -1-1), 2 N -1-1]

• Example N=3,[-(4-1), 4-1] = [-3, 3]

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 31/60

Sign/Magnitude Numbers

• Problems Addition doesn’t work naturally Example: 5 + (-5)

0101+ 1101

10010Two representations of 0 ( ± 0)

0000 (+0)1000 (-0)

31

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 32/60

Two’s Complement Numbers

• Ok, so what’s a solution to these problems? 2’s complement numbers!

• Don’t have same problems as sign/magnitude

numbers Addition works fineSingle representation for 0

• So, hardware designers like it and uses 2’scomplement number system whendesigning CPU

32

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 33/60

How to Make 2’s Complement Numbers?

• Reversing the sign of a two’s complement

numberMethod:1. Flip (Invert) the bits2. Add 1

Example

-7 : 2’s complement number of +7

0111 (+7) 1000 (flip all the bits)+ 1 (add 1)

1001 (-7)

33

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 34/60

Two’s Complement Numbers

• The most significant bitstill indicates the sign

If MSB == 1, a negativenumberIf MSB == 0, a positivenumber

• Range of an N -bit two’scomplement number[-2N -1, 2 N -1-1]

• Example N=3,[-(4), 4-1] = [-4, 3]

34

Signed

Decimal

2’s complement Unsigned

Decimal

0 000 0

1 001 1

2 010 2

3 011 3

-4 100 4

-3 101 5

-2 110 6

-1 111 7

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 35/60

Two’s Complement Examples

• Take the two’s complement of 01102

1001 (flip all the bits)+ 1 (add 1)

1010

• Take the two’s complement of 1101 2

0010 (flip all the bits)+ 1 (add 1)

0011

35

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 36/60

Two’s Complement Addition

• Add 6 + (- 6) using two’s complement numbers

• Add -2 + 3 using two’s complement numbers

36

+01101010

10000

111

+11100011

10001

111

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 37/60

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 38/60

Sign-Extension

• Sign bit is copied into most significant bits.Number value remains the same

• Examples4-bit representation of 3 = 00118-bit sign-extended value:

4-bit representation of -5 = 10118-bit sign-extended value:

38

1111 1011

0000 0011

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 39/60

Zero-Extension

• Zeros are copied into most significant bits.Number value may change.

• Examples4-bit value = 00118-bit zero-extended value:

4-bit value = 10118-bit zero-extended value:

39

0000 1011

0000 0011

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 40/60

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 41/60

Online Tools

• Cisco’s binary teaching game Set and reset bits to display a binary representationof specific decimal numbershttp://forums.cisco.com/CertCom/game/binary_game_page.htm

• Number converter And online number converter from binary to hex anddecimal and back.

http://www.free-test-online.com/binary/signed_converter.html

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 42/60

Zoom-in a System Component

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 43/60

Logic Gates

• Logic gates perform logic functions such as NOT(inversion), AND, OR, NAND, NOR, etc.Single-input logic gates

• NOT gate, buffer

Two-input logic gates• AND, OR, XOR, NAND, NOR, XNOR etc

Multiple-input logic gates• AND, OR, XOR, NAND, NOR, XNOR etc

43

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 44/60

Logic Function and Truth Table

F ABC

Y

Y

10

101001

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 45/60

Single-Input Logic Gates

45

NOT

Y = A

A Y 0 1

1 0

A Y

BUF

Y = A

A Y 0 0

1 1

A Y

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 46/60

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 47/60

More Two-Input Logic Gates

47

XNOR

Y = A + B

A B Y 0 0

0 1

1 0

1 1

AB

Y

XOR NAND NOR

Y = A + B Y = AB Y = A + B

A B Y 0 0 0

0 1 1

1 0 1

1 1 0

A B Y 0 0 1

0 1 1

1 0 1

1 1 0

A B Y 0 0 1

0 1 0

1 0 0

1 1 0

AB

Y AB

Y AB

Y

• 2 input XOR (Exclusive OR) is “true” if either A or B (not both) is true

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 48/60

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 49/60

Transistor

• Transistor is a three-ported voltage-controlled switch

• Electronic switch, a path exists when the Switch Control isclosed• If (Open) OUTPUT = unknown ; Switch is open ( OFF )• Else OUTPUT = INPUT ; Switch is closed ( ON )

• Analogy — water through a pipe: the gate acts like a valve,allowing/preventing a flow between the source and drain

49

Hmmm, what is it really built from?

INPUT OUTPUT

Switch Control

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 50/60

Th A l f A T i

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 51/60

The Analogy of A Transistor

Cross Section

An N-Channel Metal-Oxide Semiconductor Field Effect Transistor (MOSFET)

Source Drain

Switch Control (Gate)

OS Si l f

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 52/60

MOS Signal Transfer Property

Gate Path

0 volts Conduct

2.9 volts Open

Gate

Drain

Source

Gate

Source

Drain

Gate Path0 volts Open

2.9 volts Conduct

pMOS

nMOS

• Transmits 1 well• Transmits 0 poorly

• Transmits 0 well• Transmits 1 poorly

CMOS

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 53/60

CMOS

V DD

In Out

GND

p-type

n-type

• CMOS is used to build the vast majority of all transistorsfabricated today

pMOS transistors pass good 1’s, so connect source to V DD nMOS transistors pass good 0’s, so connect source to GND

= 2.9 volts

In Out

0 volts 2.9 volts

2.9 volts 0 volts

I i I (NOT G )

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 54/60

54

It is an Inverter (NOT Gate)

V DD

A Y

GND

N1

P1

NOT

Y = A

A Y 0 1

1 0

A Y

A P1 N1 Y0 ON OFF 1

1 OFF ON 0

NAND G t

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 55/60

55

NAND Gate

A

B

Y

N2

N1

P2 P1NAND

Y = AB

A B Y 0 0 1

0 1 1

1 0 1

1 1 0

AB

Y

A B P1 P2 N1 N2 Y

0 0 ON ON OFF OFF 1

0 1 ON OFF OFF ON 1

1 0 OFF ON ON OFF 1

1 1 OFF OFF ON ON 0

E t C dit Q ti

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 56/60

Extra Credit Question

• ProblemDesign and build a mechanical NOR gateFree to use any mechanical parts

• tubes, rods, wheels, valves, pipes

No magnets and electronic components allowed

• Competition ruleSend your design by Wednesday midnightFirst five working designs will get 3 points on the finalgrades3 additional points if the winner can build it anddemonstrate it in class

56

A l ti l E i

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 57/60

Analytical Engine

• Charles Babbage’s Analytical Engine • Mechanical decimal general purpose computer• Steam engine, punchcards, gears• CPU complete by death in 1871• The first complete Babbage Engine was completed in London in

2002, 153 years after it was designed.

Another age must be the judge

Z1

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 58/60

Z1

• 1938 Konrad Zuse: the Z1• First binary programmable computer, completely mechanical• Punchcard input, processing implemented with metal plates

58

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 59/60

Next Class

8/13/2019 CompArch Lec01 Number System and Gates

http://slidepdf.com/reader/full/comparch-lec01-number-system-and-gates 60/60

Next Class

• Combinational Logic