cs1q computer systems lecture 5 simon gay. lecture 5cs1q computer systems - simon gay2 where we are...

20
CS1Q Computer Systems Lecture 5 Simon Gay

Upload: adela-barton

Post on 28-Dec-2015

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

CS1Q Computer SystemsLecture 5

Simon Gay

Page 2: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 2

Where we are

Global computing: the Internet

Networks and distributed computing

Application on a single computer

Operating System

Architecture

Digital Logic

Electronics

Physics

Working upwards within thedigital logic level, in order tounderstand architecture in more detail

Page 3: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 3

Processing Digital InformationWe’ll start with some fundamental operations on binary digits andwork up to more complicated operations.

If x and y are binary digits (either 0 or 1) then

x AND y

is a binary digit, defined by

x AND y = 1 if x = 1 and y = 1 = 0 otherwise

AND

Page 4: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 4

The Truth Table for ANDIf we think of the binary values as true and false instead of 1 and 0then AND has its ordinary meaning:

x AND y is true if x is true and y is true

A truth table makes the meaning explicit:

x y x AND y0 0 00 1 01 0 01 1 1

x y x AND yf f ff t ft f ft t t

True/false, high/low, 1/0 are all alternatives. We will usually stickto 1/0 in truth tables.

Page 5: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 5

Diagrammatic RepresentationThere is a conventional notation for diagrams in which the ANDoperation is represented by:

xy x AND y

To make it easier to draw diagrams, we might just use a labelled box instead:

xy x AND yand2

Page 6: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 6

ORIf x and y are binary digits (either 0 or 1) then

x OR y

is a binary digit, defined by x OR y = 1 if x = 1 or y = 1, or both = 0 otherwise

x y x OR y0 0 00 1 11 0 11 1 1

Truth table: Diagram:

xy x OR y

xy x OR yor2

Page 7: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 7

Example: Majority VotingImagine that three people have to vote either Yes (represented by 1)or No (represented by 0). The overall result is the majority decision.

If x, y, z stand for the three votes, and r stands for the result, thenwe can write

r = (x AND y) OR (y AND z) OR (z AND x)

Diagrammatically:

This can be viewed as a circuit diagram and implementedelectronically. The components are then called logic gates.

Page 8: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 8

Example: Majority VotingWe can use a truth table to check that the circuit works.

yx z ba c ed r00 0 00 0 00 000 1 00 0 00 010 0 00 0 00 010 1 10 0 01 101 0 00 0 00 001 1 00 1 1 111 0 01 0 01 111 1 11 1 11 1

0

The result r is 1 in thefour cases when two ofx, y, z are 1.

Page 9: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 9

What We Have DefinedWe have defined a function with three boolean (truth value)arguments (inputs) and a boolean result (output). Mathematically, wehave

BBBBmajority :

if B is the set {0,1}. The truth table (columns x, y, z, r) shows theresult (an element of B) for each combination of inputs(each combination of inputs is an element of ). BBB

The truth table defines a subset of whose elementscorrespond to the rows: ((0,0,0),0), ((0,0,1),0), etc. It is a relationwith attributes and B.

BBBB )(

BBB

For each element (x,y,z) of the relation contains exactly onetuple whose input attributes match (x,y,z). This property is what makesit into a function. The output attribute of this tuple is the result r.

BBB

Page 10: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 10

Majority Voting in AdaWe can make use of the logical operations to express the majorityvoting function in Ada.

function Majority(x, y, z : Boolean) return Boolean isbegin

return (x and y) or (y and z) or (z and x);end Majority;

This gives a flavour of hardware description languages, which areused in preference to circuit diagrams for complex designs.

Page 11: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 11

NOT

x NOT x0 11 0

It turns out that AND and OR are not sufficient to define all functionson binary digits. (Because, any function constructed from AND andOR must output 1 if all inputs are 1.) The missing ingredient is NOT.

x NOT x

x NOT xnot

Again, if we think in terms of truth values, NOT has its familiarmeaning.

A NOT gate is often called an inverter.

Page 12: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 12

(AND or OR) and NOTBy using AND, OR and NOT in combination, it is possible to defineany desired function on binary numbers. We will see how to do thisin a few lectures’ time.

Perhaps surprisingly, we only need NOT and just one of AND and OR.

Exercise: work out the truth table for the following circuit and checkthat it is equivalent to the OR function.

Page 13: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 13

OR from AND and NOT

x y ba c z0 00 11 01 1

Page 14: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 14

AND from OR and NOT

x y ba c z0 00 11 01 1

Exercise: check that this circuit is equivalent to the AND function.

Page 15: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 15

One Fundamental OperationEven more remarkably, it is possible to build up all functions fromcombinations of just one operation: the NAND operation.

x y x NAND y0 0 10 1 11 0 11 1 0

xy x NAND y

xy x NAND ynand2

NAND is short for NOT AND. We can check that

x NAND y = NOT (x AND y)

Page 16: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 16

NAND is UniversalAssuming that we have NAND, we can define the other operations:

NOT x = x NAND xx AND y = NOT (x NAND y) = (x NAND y) NAND (x NAND y)x OR y = (NOT x) NAND (NOT y) = (x NAND x) NAND (y NAND y)

Exercise: check these equations by constructing truth tables.

x x NAND x01

x y x NAND y0 00 11 01 1

NOT(x NAND y)

Page 17: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 17

Another Fundamental OperationThe NOR operation is also sufficient for building all functions.

x y x NOR y0 0 10 1 01 0 01 1 0

xy x NOR y

xy x NOR ynand2

NOR is short for NOT OR. We can check that

x NOR y = NOT (x OR y)

Page 18: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 18

NOR is UniversalAssuming that we have NOR, we can define the other operations:

NOT x = x NOR xx OR y = NOT (x NOR y) = (x NOR y) NOR (x NOR y)x AND y = (NOT x) NOR (NOT y) = (x NOR x) NOR (y NOR y)

Exercise: check these equations by constructing truth tables.

x x NOR x01

x y x NOR y0 00 11 01 1

NOT(x NOR y)

Exercise: prove that NAND and NOR are the only universal operations.

Page 19: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 19

XORIf x and y are binary digits then x XOR y

is a binary digit, defined by

x XOR y = 1 if either x = 1 or y = 1, but not both = 0 otherwise

x y x XOR y0 0 00 1 11 0 11 1 0

Truth table: Diagram:

xy x XOR y

xy x XOR yxor2

XOR is exclusive or. OR is inclusive or.

Page 20: CS1Q Computer Systems Lecture 5 Simon Gay. Lecture 5CS1Q Computer Systems - Simon Gay2 Where we are Global computing: the Internet Networks and distributed

Lecture 5 CS1Q Computer Systems - Simon Gay 20

ImplicationImplication is a logical operation although it is not used in digitalcircuits. x => y means “x implies y” or “if x then y” or“if x is true then y is true”.

x y x => yfalse false truefalse true truetrue false falsetrue true true

ExampleIf 2+2=5 then the moon is made of cheese.

If 2+2=5 then Glasgow is in Scotland.

If Glasgow is in Scotland then 2+2=5.

If Glasgow is in Scotland then 2+2=4.

x => y is true if it is logically valid to deduce y from x. It is true in allcases except when x is true and y is false.

Note: x => y does not mean that x causes y.