digital’logiccs240/s16/slides/gates.pdf · 1/26/16 2 cs 240, fall 2014 wellesley cs...

6
1/26/16 1 WELLESLEY CS CS 240, Fall 2014 Digital Logic Gateway to computer science Devices (transistors, etc.) SolidState Physics Hardware Digital Logic Microarchitecture Instruction Set Architecture Operating System Programming Language Compiler/Interpreter Program, Application Software WELLESLEY CS CS 240, Fall 2014 Boolean value ( bit): 0 or 1 basis of all digital data representations Boolean functions (AND, OR, NOT, …): basis of all digital computations Electronically: bit = high voltage vs. low voltage Boolean functions = logic gates, built from transistors 0.0V 0.5V 2.8V 3.3V 0 1 0 3 WELLESLEY CS CS 240, Fall 2014 Truth table Transistors (more in lab) Base Collector Emitter If Base voltage is high: Current may flow freely from Collector to Emitter. If Base voltage is low: Current may not flow from Collector to Emitter. V in V out low high high low in out 0 1 1 0 in out F T T F = = NOT gate +V cc (Supply Voltage) (Ground) resistor V in V out

Upload: others

Post on 18-Mar-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Digital’Logiccs240/s16/slides/gates.pdf · 1/26/16 2 CS 240, Fall 2014 WELLESLEY CS Tiny(electronic(devices(that(compute(basic(Boolean(functions. Digital’Logic’Gates NAND Vin

1/26/16

1

WELLESLEY CSCS 240, Fall 2014

Digital  Logic

Gateway  to  computer  science

WELLESLEY CSCS 240, Fall 2014

Devices  (transistors,  etc.)

Solid-­‐State   Physics

Hardw

are

Digital  LogicMicroarchitecture

Instruction   Set  Architecture

Operating   System

Programming   Language

Compiler/Interpreter

Program,   Application

Software

WELLESLEY CSCS 240, Fall 2014

Boolean  value  (bit):  0  or  1basis  of  all  digital  data  representations

Boolean   functions   (AND,  OR,  NOT,  …):basis  of  all  digital  computations

Electronically:bit  =  high  voltage  vs.  low  voltage

Boolean  functions  =  logic  gates,  built  from  transistors

0.0V0.5V

2.8V3.3V

0 1 0

3

WELLESLEY CSCS 240, Fall 2014

Truth   table

Transistors (more  in  lab)

Base

Collector

Emitter

If  Base voltage   is  high:Current  may   flow   freelyfrom  Collector to  Emitter.

If  Base voltage   is  low:Current  may  not  flowfrom  Collector to  Emitter.

Vin Vout

low   highhigh low

in out0 11 0

in outF TT F

==

NOT  gate

+Vcc (SupplyVoltage)

(Ground)

resistor

Vin

Vout

Page 2: Digital’Logiccs240/s16/slides/gates.pdf · 1/26/16 2 CS 240, Fall 2014 WELLESLEY CS Tiny(electronic(devices(that(compute(basic(Boolean(functions. Digital’Logic’Gates NAND Vin

1/26/16

2

WELLESLEY CSCS 240, Fall 2014

Tiny  electronic  devices  that  compute  basic  Boolean  functions.

Digital  Logic  Gates

NAND

Vin

+Vcc

VoutV1

+Vcc

Vout

V2

ex

NOT

Vin Vout

0 11 0

0 101

V1

V2

WELLESLEY CSCS 240, Fall 2014

Integrated  Circuits  (invented  1950s)Gates  are  manufactured  in  units  called  integrated  circuits.From  SSI  (tens)  to  VLSI  (hundreds  of  thousands  to  billions)

Wafer

Chip

WELLESLEY CSCS 240, Fall 2014

Five  basic  gates:  define  with  truth  tables

NOT NAND NOR

AND OR

0 11 0

0 10 1 11 1 0

0 101

0 101

0 101

exWELLESLEY CSCS 240, Fall 2014

Boolean  Algebrafor  combinational  logic

A

BA  B(A  ·∙  B)

A

BA  +  B

A A A A

inputs = variableswires = expressionsgates = operators/functionscircuits = functions

AND  =  Boolean  product OR  =  Boolean  sum

NOT  =  inverse  or  complement wire  =  identity

·∙ 0 1

0 0 0

1 0 1

+ 0 1

0 0 1

1 1 1

0 1

1 00 0

1 1

Page 3: Digital’Logiccs240/s16/slides/gates.pdf · 1/26/16 2 CS 240, Fall 2014 WELLESLEY CS Tiny(electronic(devices(that(compute(basic(Boolean(functions. Digital’Logic’Gates NAND Vin

1/26/16

3

WELLESLEY CSCS 240, Fall 2014

CircuitsConnect  inputs  and  outputs  of  gates  with  wires.Crossed  wires  touch  only  if there  is  a  dot.

What   is   the  output  if  A=1,  B=0,  C=1?What   is   the  truth   table  of  this  circuit?What   is  an  equivalent   Boolean  expression?

ex

=

AB

C

WELLESLEY CSCS 240, Fall 2014

TranslationConnect  gates  to  implement  these  functions.    Check  with  truth  tables.A  one-­‐to-­‐one  translation  is  straightforward  and  bidirectional.

F  =   (AB  +  C)D

Z  =  W  +   (X  +  WY)

ex

WELLESLEY CSCS 240, Fall 2014

Identity  law,  inverse  law

A

B=

A

B

A  +  B

0

A A A

A  +  B

0  +  A=

A

A  A= A

0

Note  on  notation:   bubble  =  inverse/complementWELLESLEY CSCS 240, Fall 2014

Commutativity,  Associativity

A

B=

=

A  +  BB

AB  +  A

AB

C

(AB)CAB A

BC

A(BC)

BC

Page 4: Digital’Logiccs240/s16/slides/gates.pdf · 1/26/16 2 CS 240, Fall 2014 WELLESLEY CS Tiny(electronic(devices(that(compute(basic(Boolean(functions. Digital’Logic’Gates NAND Vin

1/26/16

4

WELLESLEY CSCS 240, Fall 2014

Idempotent  law,  Null/Zero  law

0

A

A A

0  A=

A

A0

A  +  A =

WELLESLEY CSCS 240, Fall 2014

DeMorgan's Law(double  bubble,  toil  and  trouble,  in  Randy's  words...)

AA  +  B

B

A

B=

AB A  B=

AB

A  +  B =

A  +  B

Note  on  notation:   bubble  =  inverse/complement

WELLESLEY CSCS 240, Fall 2014

One  law,  Absorption  lawWrite   truth  tables.    Do  they  correspond   to  simpler  circuits?

A

1

A  +  1 =

A A  +  AB

B

=

AB

exWELLESLEY CSCS 240, Fall 2014

NAND  is  universal.

All  Boolean   functions  can  be  implemented   using  only  NANDs.Let's  prove   it!    Build  NOT,  AND,  OR,  NOR,  using  only  NAND  gates.

ex

Page 5: Digital’Logiccs240/s16/slides/gates.pdf · 1/26/16 2 CS 240, Fall 2014 WELLESLEY CS Tiny(electronic(devices(that(compute(basic(Boolean(functions. Digital’Logic’Gates NAND Vin

1/26/16

5

WELLESLEY CSCS 240, Fall 2014

XOR:  Exclusive  OR

Output  =  1  if  exactly  one  input  =  1.

Truth  table: Build  from  earlier  gates:

Often  used  as  a  one-­‐bit  comparator.

Video  game  designers,  Halloween  costumers  extraordinaire,  sci-­‐fi/fantasy  screenwriters,I  have  an  idea…

exWELLESLEY CSCS 240, Fall 2014

Gates of XOR

Exclusive preview or something.© 2015 Ben Wood

WELLESLEY CSCS 240, Fall 2014

Larger  gatesBuild  a  4-­‐input  AND  gate  using  any  number  of  2-­‐input  gates.

exWELLESLEY CSCS 240, Fall 2014

Circuit  simplificationCan  we  find  a  simpler  circuit  that  performs  the  same  function?

Start  with  an  equivalent  Boolean  expression,  then  simplify  with  algebra.F(A,  B,  C)  =  

Why  simplify?Smaller  =  cheaper,   faster,   cooler,  

easier   to  design/build.

Check  the  answer  with  a  truth  table.

ex

Page 6: Digital’Logiccs240/s16/slides/gates.pdf · 1/26/16 2 CS 240, Fall 2014 WELLESLEY CS Tiny(electronic(devices(that(compute(basic(Boolean(functions. Digital’Logic’Gates NAND Vin

1/26/16

6

WELLESLEY CSCS 240, Fall 2014

Circuit  derivation:  code  detectorsAND  gate  +  NOT  gates  =  code  detector,  recognizes  exactly  one  input  code.

Design  a  4-­‐input  code  detector  to  output  1  if  ABCD  =  1001,  and  0  otherwise.

Design  a  4-­‐input  code  detector  to  accept  two  codes  (ABCD=1001,  ABCD=1111)  and  reject  all  others.    (accept  =  1,  reject  =  0)

ABCD

exWELLESLEY CSCS 240, Fall 2014

Circuit  derivation:  sum-­‐of-­‐products formlogical   sum  (OR)of  products  (AND)of  inputs  or  their   complements   (NOT)

Draw  the  truth  table  and  design  a  sum-­‐of-­‐products  circuit for  a  4-­‐input  code  detector  to  accept  two  codes  (ABCD=1001,  ABCD=1111)  and  reject  all  others.  How  are  the  truth  table  and  the  sum-­‐of-­‐products  circuit  related?

ex

WELLESLEY CSCS 240, Fall 2014

Voting  machinesA  majority  circuit outputs  1  if  and  only  if  a  majority  of  its  inputs  equal  1.Design  a  majority  circuit  for  three  inputs.    Use  a  sum  of  products.

A B C Majority0 0 0 00 0 1 00 1 0 00 1 1 11 0 0 01 0 1 11 1 0 11 1 1 1

ex

Triply  redundant  computers  in  spacecraft• Compute   everything  on   three  separate   devices  and  

compare  answers.    Majority   wins.• Cosmic   rays  can   flip  bits  on  wires,   especially   in   space.• Triple   redundancy  survives   failure   in  one  device.• Space  program  also   hastened   Integrated  Circuits.

WELLESLEY CSCS 240, Fall 2014

Margaret  Hamilton (speaking  of  space  and  reliability)

Led  software  team  for  Apollo  11 Guidance  Computer.Developed  software  engineering  techniques  for  correctness  and  reliability.Coined  "software  engineering".Software  avoided  mission  abort  on  first  moon  landing!

Apollo  11  code  print-­‐out