You are on page 1of 60

COSC3330 Computer Architecture

Lecture 1. Number System and Logic Gates

Instructor: Weidong Shi (Larry), PhD Computer Science Department University of Houston

Today
Numbers Logic gates

1000 Apples in 10 Boxes


117 Apples

How to arrange 1000 apples in 10 boxes so that any number of apples can be picked in terms of boxes?

A Computer System
What are there inside a computer?

CPU
FSB (Front-Side Bus)

Main Memory (DDR2)

North Bridge
DMI (Direct Media I/F)

South Bridge

Bottom Layer of a Computer


Each component inside a computer is basically made based on analog and digital circuits
Analog
Continuous signal

Digital
Only knows 1 and 0

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


In fact, everything in this world is analog
For example, sound, light, electric signals are all analog since they are 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)

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


Digital circuit treats a signal above a certain level as 1 and a signal below a certain level as 0
Different components in a computer have different voltage requirements (Voltage requirements change as the technology
advances)

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

1
Not determined

0V
7

0
time

Logic Levels
Define a range of voltages to represent 1 and 0 Define different ranges for outputs and inputs to allow for noise in the system
Noise is anything that degrades the signal For example, a gate (driver) could output a 5 volt signal but, because of losses in the wire and other noise, the signal could arrive at the receiver with a degraded value, for example, 4.5 volts
Noise Driver 5V
8

Receiver 4.5 V

Logic Levels
Driver Receiver

Output Characteristics Logic High Output Range VO H

VDD

Input Characteristics Logic High Input Range Forbidden Zone VIH VIL Logic Low Input Range
Noise Margin NMH = VOH VIH NML = VIL VOL 9

NMH

VO L Logic Low Output Range

NML

GND

Digital vs. Analog


Analog
video wireless signal

Digital

music

10

DSP Digital Signal Processing


Analog Computer
a bit loud

Digital Computer
DSP OUTPUT

ADC 1010
1001

DAC

Number Systems
Analog information (video, sound etc) is converted to a digital format for processing Computer processes information in digital Since digital knows 1 and 0, we use different number systems in computer
Binary and Hexadecimal numbers

12

Number Systems - Decimal


Decimal numbers
Most 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) 537410 = 5 x 103 + 3 x 102 + 7 x 101 + 4 x 100

N-digit number represents one of 10N possibilities


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

13

Number Systems - Binary


Binary numbers
Bit represents one of 2 values: 0 or 1 Each column of a binary number has 2x the weight of the previous column
Binary number has 2 as its base
ex) 101102 = 1 x 24 + 0 x 23 + 1 x 22 + 1 x 21 + 0 x 20 = 2210

N-bit binary number represents one of 2N possibilities


ex) 3-bit binary number represents one of 8 possibilities: 0 ~ 7

14

Counting Binary Numbers


0 1 2 3 4 5 6 7 8
0 1 10 11 100 101 110

111
1000

Power of 2
20 21 22 23 24 25 26 27 = = = = = = = = 28 = 29 = 210 = 211 = 212 = 213 = 214 = 215 =

16

Power of 2
20 21 22 23 24 25 26 27 = = = = = = = = 1 2 4 8 16 32 64 128 28 = 256 29 = 512 210 = 1024 211 = 2048 212 = 4096 213 = 8192 214 = 16384 215 = 32768

* Handy to memorize up to 29
17

Number Systems - Hexadecimal


Hexadecimal numbers
Writing long binary numbers is tedious and error-prone We group 4 bits to form a hexadecimal (hex)
A hex represents one of 16 values
0, 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 the previous column
Hexadecimal number has 16 as its base ex) 2ED16 = 2 x 162 + E (14) x 161 + D (13) x 160 = 74910

N-hexadigit number represents one of 16N possibilities


ex) 2-hexadigit number represents one of 162 possibilities: 0 ~ 255

18

Number Systems
Hex Number 0 1 Decimal Equivalent 0 1 Binary Equivalent 0000 0001

2
3 4 5 6

2
3 4 5 6

0010
0011 0100 0101 0110

7
8 9 A B

7
8 9 10 11

0111
1000 1001 1010 1011

C
D E F

12
13 14 15 19

1100
1101 1110 1111

Number Conversions Hexadecimal to binary conversion:


Convert 4AF16 (also written 0x4AF) to binary number 0100 1010 11112

Hexadecimal to decimal conversion:


Convert 0x4AF to decimal number 4162 + A (10)161 + F (15)160 = 119910

20

Number Conversions
Convert 7510 to binary number

2 2

75 37 2 18 2 9 2 4 2 2

1 1 0 1 0 0 7510 = 100 10112

2 1
0

Bits, Bytes, Nibbles Bits (b)


10010110
most significant bit least significant bit

Bytes & Nibbles


Byte (B) = 8 bits
Used everyday

byte

10010110
nibble

Nibble (N) = 4 bits


Not commonly used

CEBF9AD7
most significant byte
22

least significant byte

KB, MB, GB
In computer, the basic unit is byte (B) And, we use KB, MB, GB many many many times
210 = 1024 = 1KB (kilobyte) 220 = 1024 x 1024 = 1MB (megabyte) 230 = 1024 x 1024 x 1024 = 1GB (gigabyte) 240 250 260 270 = = = = 1TB (terabyte) 1PB (petabyte) 1EB (exabyte) 1ZB (zettabyte)

How about these?

Number of atoms in the universe (estimated) 2266


23

Quick Checks
222 =?
22 220 = 4 Mega

How many values can a 32-bit variable represent?


22 230 = 4 Giga

Suppose that you have 2GB main memory in your computer. How many bits you need to address (cover) 2GB?
21 230 = 2 GB, so 31 bits

24

Addition Decimal

11 3734 + 5168 8902


11 1011 + 0011 1110
25

carries

Binary

carries

Binary Addition Examples Add the following 4-bit binary numbers

1001 + 0101

1011 + 0110
0001

1110

26

Overflow
Digital systems operate on a fixed number of bits Addition overflows when the result is too big to fit in the available number of bits Example:
add 13 and 5 using 4-bit numbers

11 1 1101 + 0101 10010


27

Signed Binary Numbers


How does the computer represent positive and negative integer numbers? There are 2 ways
Sign/Magnitude Numbers Twos Complement Numbers

28

Sign/Magnitude Numbers
1 sign bit, N-1 magnitude bits Sign bit is the most significant (left-most) bit
Negative number: sign bit = 1 Positive number: sign bit = 0

Example: 4-bit representations of 5: +5 = 01012 - 5 = 11012

29

Sign/Magnitude Numbers
Signed Decimal 0 1 2 3 -0 -1 Sign/Magnitude Numbers Unsigned Decimal 0 1 2 3 4 5

000 001 010 011 100 101

Range of an N-bit sign/magnitude number:


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

-2
-3

110
111

6
7

Sign/Magnitude Numbers Problems


Addition doesnt work naturally Example: 5 + (-5)

0101 + 1101 10010


Two representations of 0 (0)

0000 (+0) 1000 (-0)


31

Twos Complement Numbers


Ok, so whats a solution to these problems?
2s complement numbers!

Dont have same problems as sign/magnitude numbers


Addition works fine Single representation for 0

So, hardware designers like it and uses 2s complement number system when designing CPU
32

How to Make 2s Complement Numbers?

Reversing the sign of a twos complement number


1. Flip (Invert) the bits 2. Add 1

Method:

Example
-7: 2s complement number of +7 0111 1000 + 1 1001 (+7) (flip all the bits) (add 1) (-7)

33

Twos Complement Numbers


Signed Decimal 0 1 2 3 -4 -3 -2 -1 2s complement Unsigned Decimal 0 1 2 3 4 5 6 7

The most significant bit still indicates the sign

000 001 010 011 100 101 110 111

If MSB == 1, a negative number If MSB == 0, a positive number

Range of an N-bit twos complement number


[-2N-1, 2N-1-1]

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


34

Twos Complement Examples


Take the twos complement of 01102
1001 (flip all the bits) + 1 (add 1) 1010

Take the twos complement of 11012


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

Twos Complement Addition


Add 6 + (-6) using twos complement numbers
111 0110 + 1010 10000

Add -2 + 3 using twos complement numbers


111 1110 + 0011 10001
36

Increasing Bit Width


Sometimes, you need to increase the bit width when you design a computer
For example, read a 8-bit data from main memory and store it to a 32-bit ALU

A value can be extended from N bits to M bits (where M > N) by using:


Sign-extension Zero-extension

37

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

Examples
4-bit representation of 3 = 0011 8-bit sign-extended value: 00000011 4-bit representation of -5 = 1011 8-bit sign-extended value: 11111011

38

Zero-Extension
Zeros are copied into most significant bits.
Number value may change.

Examples
4-bit value = 0011 8-bit zero-extended value: 00000011 4-bit value = 1011 8-bit zero-extended value: 00001011

39

Number System Comparison


Number System Range

Unsigned
Sign/Magnitude Twos Complement
For example, 4-bit representation:

[0, 2N-1]
[-(2N-1-1), 2N-1-1] [-2N-1, 2N-1-1]

-8

-7

-6

-5

-4

-3

-2

-1

10 11 12 13 14 15

Unsigned

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111

Two's Complement Sign/Magnitude

1111 1110 1101 1100 1011 1010 1001

0000 1000

0001 0010 0011 0100 0101 0110 0111

40

Online Tools
Ciscos binary teaching game
Set and reset bits to display a binary representation of specific decimal numbers
http://forums.cisco.com/CertCom/game/binary_game_page.htm

Number converter
And online number converter from binary to hex and decimal and back.
http://www.free-test-online.com/binary/signed_converter.html

Zoom-in a System Component

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

Logic Function and Truth Table


A B C

F
Y
0 1 1 0 1 0 0 1

Single-Input Logic Gates

NOT
A Y=A A 0 1 Y 1 0 Y

BUF
A Y=A A 0 1 Y 0 1 Y

45

Two-Input Logic Gates

AND
A B Y = AB A 0 0 1 1 B 0 1 0 1 Y 0 0 0 1
A 0 0 1 1

OR
Y
A B Y Y=A+B B 0 1 0 1 Y 0 1 1 1

46

More Two-Input Logic Gates

XOR
A B Y Y=A+B A 0 0 1 1 B 0 1 0 1 Y 0 1 1 0 A B

NAND
Y Y = AB A 0 0 1 1 B 0 1 0 1 Y 1 1 1 0 A B

NOR
Y Y=A+B A 0 0 1 1 B 0 1 0 1 Y 1 0 0 0 A B

XNOR
Y Y=A+B A 0 0 1 1 B 0 1 0 1 Y

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

47

BTW, How Logic Gates Are Built?


What we saw so far are just symbols, right? What are those symbols built from in the real world?
NOT
A Y=A A 0 1 Y 1 0 Y A Y=A A 0 1 Y 0 1
A 0 0 1 1

BUF
Y
A B

AND
Y Y = AB B 0 1 0 1 Y 0 0 0 1

OR
A B Y Y=A+B A 0 0 1 1 B 0 1 0 1 Y 0 1 1 1

Transistors!
48

Transistor
Transistor is a three-ported voltage-controlled switch Electronic switch, a path exists when the Switch Control is closed
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

Switch Control

INPUT

OUTPUT

Hmmm, what is it really built from?


49

Silicon
Transistors are built out of silicon. Silicon is not a conductor Silicon crystal is an insulator -- no free electrons. Doping transforms a silicon crystal from a good insulator into a viable conductor; hence, the name semiconductor. Metal oxide silicon (MOS) transistors: Adding phosphorus produces n-type transistor Adding boron produces p-type transistor
50

Silicon powder

The Analogy of A Transistor


Switch Control (Gate) Source Drain

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

MOS Signal Transfer Property

Source Gate Drain pMOS

Gate 0 volts 2.9 volts

Path Conduct Open

Transmits 1 well Transmits 0 poorly

Drain Gate Source nMOS Gate 0 volts 2.9 volts Path Open Conduct

Transmits 0 well Transmits 1 poorly

CMOS
VDD = 2.9 volts
p-type
In Out
2.9 volts 0 volts

In

Out
n-type

0 volts 2.9 volts

GND
CMOS is used to build the vast majority of all transistors fabricated today
pMOS transistors pass good 1s, so connect source to VDD nMOS transistors pass good 0s, so connect source to GND

It is an Inverter (NOT Gate)


NOT
A Y=A A 0 1 Y 1 0
A
0
1

VDD
Y

P1 Y N1 GND
P1 N1

Y
1
0

ON
OFF

OFF
ON

54

NAND Gate
NAND
A B Y = AB A 0 0 1 1 B 0 1 0 1 Y 1 1 1 0 Y

P2 A B

P1 Y N1 N2

A 0 0 1 1

B 0 1 0 1

P1 ON ON OFF OFF

P2 ON OFF ON OFF
55

N1 OFF OFF ON ON

N2 OFF ON OFF ON

Y 1 1 1 0

Extra Credit Question


Problem Design and build a mechanical NOR gate Free to use any mechanical parts tubes, rods, wheels, valves, pipes No magnets and electronic components allowed Competition rule
Send your design by Wednesday midnight First five working designs will get 3 points on the final grades 3 additional points if the winner can build it and demonstrate it in class
56

Analytical Engine

Another age must be the judge

Charles Babbages 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.

Z1

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

Programmable Water

Paul Blikstein
59

Next Class
Combinational Logic

You might also like