Computer Science 101 Logic Gates and Simple Circuits.

25
Computer Science Computer Science 101 101 Logic Gates and Simple Logic Gates and Simple Circuits Circuits

Transcript of Computer Science 101 Logic Gates and Simple Circuits.

Computer Science Computer Science 101101

Logic Gates and Simple Logic Gates and Simple CircuitsCircuits

Transistor - Electronic Transistor - Electronic SwitchSwitch

Collector

Base

EmitterSwitch

Base High (+5v or 1)Base High (+5v or 1) Makes connection Makes connection

Base Low (0v or 0)Base Low (0v or 0) Disconnects Disconnects

Say, 500 million Say, 500 million transistors on a chip transistors on a chip 1 cm1 cm22

Change states in Change states in billionth of secbillionth of sec

Solid stateSolid state

Moore’s LawMoore’s Law

In 1965, Intel co-founder Gordon Moore saw the future. His prediction, now popularly known as Moore's Law, states that the number of transistors on a chip doubles about every two years.

GatesGates

A A gategate is an electronic device that is an electronic device that takes 0/1 inputs and produces a 0/1 takes 0/1 inputs and produces a 0/1 result.result.

NOT GateNOT Gate

+5v

Input

Ground

Input High (+5v or 1)Input High (+5v or 1) Output Low (0v or 0) Output Low (0v or 0)

Input Low (0v or 0) Input Low (0v or 0) Output High (+5v or 1)Output High (+5v or 1)

Output is opposite of Output is opposite of InputInput

Output

NOT Gate

A_A

AND GateAND Gate

+5v Output is 1 only ifOutput is 1 only if• Input-1 is 1 andInput-1 is 1 and• Input-2 is 1Input-2 is 1

OutputOutput = Input1 AND Input2 = Input1 AND Input2

Output

Input-1

Input-2

AND GateA

ABB

OR GateOR Gate

Output is 1 ifOutput is 1 if• A is 1 or ifA is 1 or if• B is 1B is 1

OutputOutput = A OR B = A OR B

+5v

Output

A BOR Gate

A

A + BB

Boolean Expression Boolean Expression PythonPython

Logical operatorsLogical operators• AND AND and (Python) and (Python)• OR OR or (Python) or (Python)• NOT NOT not (Python) not (Python)

NOT ((x>y) AND ((x=5) OR (y=3))NOT ((x>y) AND ((x=5) OR (y=3))

not((x>y) and ((x==5)or(y==3)))not((x>y) and ((x==5)or(y==3)))

while (not((x>y) and ((x==5)or(y==3)))) :while (not((x>y) and ((x==5)or(y==3)))) :……

AbstractionAbstraction In computer science, the term In computer science, the term abstractionabstraction

refers to the practice of defining and using refers to the practice of defining and using objects or systems based on the high level objects or systems based on the high level functions they provide. functions they provide.

We suppress the fine details of how these We suppress the fine details of how these functions are carried out or implemented.functions are carried out or implemented.

In this way, we are able to focus on the big In this way, we are able to focus on the big picture.picture.

If the implementation changes, our high level If the implementation changes, our high level work is not affected.work is not affected.

Abstraction ExamplesAbstraction Examples

Boolean algebra Boolean algebra - we can work with the - we can work with the Boolean expressions knowing only the Boolean expressions knowing only the properties or laws - we do not need to properties or laws - we do not need to know the details of what the variables know the details of what the variables represent.represent.

GatesGates - we can work with the logic gates - we can work with the logic gates knowing only their function (output is 1 knowing only their function (output is 1 only if inputs are …). Don’t have to know only if inputs are …). Don’t have to know how gate is constructed from transistors.how gate is constructed from transistors.

Boolean Exp Boolean Exp Logic Circuit Logic Circuit

To draw a circuit from a Boolean To draw a circuit from a Boolean expression:expression:

• From the left, make an input line for each From the left, make an input line for each variable.variable.

• Next, put a NOT gate in for each variable that Next, put a NOT gate in for each variable that appears negated in the expression.appears negated in the expression.

• Still working from left to right, build up circuits Still working from left to right, build up circuits for the subexpressions, from simple to complex.for the subexpressions, from simple to complex.

Logic Circuit: _ ____Logic Circuit: _ ____ AB+(A+B)B AB+(A+B)B

A

B

Input Lines for Variables

Logic Circuit: _ ____Logic Circuit: _ ____ AB+(A+B)B AB+(A+B)B

A

B

NOT Gate for B

_B

Logic Circuit: _ ____Logic Circuit: _ ____ AB+(A+B)B AB+(A+B)B

A

B

_Subexpression AB

_B

_AB

Logic Circuit: _ ____Logic Circuit: _ ____ AB+(A+B)B AB+(A+B)B

A

B

Subexpression A+B

_B

_AB

A+B

Logic Circuit: _ ____Logic Circuit: _ ____ AB+(A+B)B AB+(A+B)B

A

B

___ Subexpression A+B

_B

_AB

A+B____A+B

Logic Circuit: _ ____Logic Circuit: _ ____ AB+(A+B)B AB+(A+B)B

A

B

___ Subexpression (A+B)B

_B

_AB

A+B____A+B

____(A+B)B

Logic Circuit: _ ____Logic Circuit: _ ____ AB+(A+B)B AB+(A+B)B

A

B

Entire Expression

_AB

A+B____A+B

_B ____

(A+B)B

Logic Circuit Logic Circuit Boolean Exp Boolean Exp In the opposite direction, given a logic circuit, In the opposite direction, given a logic circuit,

we can write a Boolean expression for the we can write a Boolean expression for the circuit.circuit.

First we label each input line as a variable.First we label each input line as a variable.

Then we move from the inputs labeling the Then we move from the inputs labeling the outputs from the gates.outputs from the gates.

As soon as the input lines to a gate are labeled, As soon as the input lines to a gate are labeled, we can label the output line.we can label the output line.

The label on the circuit output is the result.The label on the circuit output is the result.

Logic Circuit Logic Circuit Boolean Exp Boolean Exp

A

B

_A

_B

A+B

_AB

_ AB

_ _AB+AB

_ _AB+AB

______

_ _ (AB+AB)(A+B)

______Entire Expression

Simplification RevisitedSimplification Revisited

Once we have the BE for the circuit, Once we have the BE for the circuit, perhaps we can simplify.perhaps we can simplify.

AB

BA A A

ABA

BBABA

BABABA

BA BA BA BABABA

Logic Circuit Logic Circuit Boolean Exp Boolean Exp

Reduces to:

The Boolean TriangleThe Boolean Triangle

Boolean Expression

TruthTable

LogicCircuit

The Boolean TriangleThe Boolean Triangle

Boolean Expression

TruthTable

LogicCircuit