how computers work … and how you can work them. art 311 lecture 04 dr. j parker

67
How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Upload: esmond-walker

Post on 18-Jan-2016

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How Computers Work

… and how you can work them.

Art 311 Lecture 04

Dr. J Parker

Page 2: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Key Concept #3 - Interface

General: an interface is the point of contact between two objects.

Computer: place where computer-human communication happens.

Computer interfaces are designed and built by humans.

(Sadly, often by computer programmers)

Page 3: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Key Concept #3 - Interface

Traditional interface devices:

Mouse, keyboard, touch-pad, monitor, sound card.

Interface processes: typing, mouse gestures, computer graphics

(all require computer programs = software)

Page 4: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Key Concept #3 - Interface

New media uses dynamic mechanisms for the direction of computer activities.

Level 1: keyboard/mouse control of dynamic (moving, changing) objects.

an avatar

Page 5: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Key Concept #3 - Interface

New media uses dynamic mechanisms for the direction of computer activities.

Level 3: Tangible interfaces where a person interacts with digital information through the physical environment.

(Mouse) touch screen, orientation detection, etc.

Page 6: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Key Concept #3 - Interface

New media uses dynamic mechanisms for the direction of computer activities.

Level 3: Pervasive interfaces where a person interacts with devices using natural human means without a contact device.

Vision, speech, bluetooth/RFID.

Page 7: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Key Concept #3 - Interface

Interface is a key concept because interfaces play an active role in how we perceive the information in the message.

EG: If we expect a picture, we should get one.

… unless the message is one of contrast/contradiction.

Page 8: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

What is a Computer?

There are many types of computer, but the typical PC or MAC or Linux computer is what we are going to discuss. It is vastly the most common type.

It is referred to as a stored program digital computer (von Neumann machine)

Page 9: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Properties of a computer

1. Computers can only manipulate numbers.

To get a computer to create a picture or music, we must device some sort of code that allows pictures and music to be made into numbers.

This is an encoding, and computers use many of them

Page 10: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Computers can only manipulate numbers.

A simple encoding: characters.

On a computer, the letter ‘A’ is stored as the number 65, ‘B’ is 66 …

The number ‘0’ is 48, ‘1’ is 49. and so on.

This is the ASCII (American Standard Code for Information Interchange) code. There are others.

Page 11: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

ASCII

Page 12: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Computers can only manipulate numbers.

Strings are sequences of characters.

E.G. “This is a string”Is stored as a set of adjacent numbers:84 104 105 115 32 105 115 32 97 32 115 116

114 105 110 103

This is called the representation of the string, and we’ll talk about that sort of thing in the next class.

Page 13: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Computers can only manipulate numbers.

Computers can do the following things to numbers:

Add them (and subtract)Store in memoryGet from memorySome can multiply/divideLogical: AND, OR, NOT etc

Page 14: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Computers can only manipulate numbers.

Memory is a place where numbers can be stored for later use.

Each place in memory can hold a number.

Each place in memory has an address by which the location is known. To store/retrieve a number in memory one needs and address.

Page 15: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

1248

163264

128256512

1024

012345678910

Address Memory

Page 16: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Accessing memory in a computer

Ask: Give me the contents of location number 8 (address 8). Then it can be changed (EG ‘add to 7’)

Ask: Store 15 into location 8

Page 17: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Accessing memory in a computer

Most times one has to get the contents of memory before doing something to it:

Get location 6 (=64)Get location 5 (=32)Add them together (=96)Store result in location 7 (This is a computer program!)

Page 18: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Properties of computers

2. Computers operate using electricity.

Electronic computers must use some electronic means to store and retrieve numbers.

There must be a way to represent numbers using electricity – voltages, current, etc.

What do you know about electricity?

Page 19: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Electricity

Not everyone is good with electricity, so here’s a quick simple summary:

Electricity is a motion of electrons through a conductor. Common analogy is that of water through a pipe.

Water pressure = voltage (difference between the two ends).

Current = amount of water flow (amps)Resistance = friction with the pipe. (Ohms)

Page 20: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Electricity

Electrons have a negative charge. If electrons are like ‘water’ then here is a visual analogy:

-- - - - - - ---- --- - - -

-- - - - - - -- - --- - -- - - - - - - - - - - -

Flow is from more electrons to fewer (more‘negative’ to less ‘negative’ (more ‘positive’)

Page 23: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Electricity

So how can we represent numbers?

Hmm, 10 digits. Maybe 10 voltages? Leads to complex and slow circuits.

ENIAC

Page 24: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Properties of computers

2. Computers use binary numbers, not decimal.

Electronic computers must use some electronic means to store and retrieve numbers, and binary (base 2) is much more effective in electronic circuits.

But what are binary numbers?

Page 25: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Binary/Decimal numbers

Grade 3 math coming up …

Our standard number system is Base 10, meaning that there are 10 digits 0, 1, …9

10 is the base of the number system, meaning that the representation depends on it.

We probably use 10 as a base because we have 10 fingers

Page 26: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Binary/Decimal numbers

The number 342 in base 10 is really 3 x 100 + 4 x10 + 2 or 3x102 + 4x101 + 2x100

The exponent is the digit position, counted right to left starting at 0.

Position 3 2 1 0 103=1000 102=100 101=10 100=1 x x x x 0 3 4 2 300 + 40 + 2 = 342

173 = 100 + 70 + 3 = 1x102 + 7x101 + 3x100

Page 27: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Binary/Decimal numbers

Why does the base have to be 10? It does not. How about base 8? 82 = 64 81 = 8 80=1So 342 in base 8 is: 3x82 + 4x81 + 2x80 or 3 x 64 + 4 x8 + 2 or 192 + 32 + 2 = 226 (if it were in

base 10)

Base is shown as a subscript: 342 base 10 is 34210 342 base 8 is 3428

Page 28: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Binary/Decimal numbers

Numbers always represent the same things

so 1210 means this many: | | | | | | | | | | | |

148 = 1210 and means this many: | | | | | | | | | | | |

The value of the number 12 stays the same, symbolic

representation can vary depending on symbols set and

base.

Babylonians used base 60!

Page 29: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Binary/Decimal numbers

We can do math in much the same way irrespective of base.

Listen carefully:

Page 30: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Binary/Decimal numbers

3 4 2 - 1 7 3

Starting at the right do 2-3.Can’t do that since 2 < 3, so we borrow one (which is

101 = 10) from the next place left. 12 – 3 = 9 3 3 12 - 1 7 3 9

Page 31: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Binary/Decimal numbers

3 3 2 - 1 7 3

Now the next column is 3 - 7.As before, 3 < 7, so we borrow one (which is 102=100)

from the next place left – it was 3, now becomes 2 13 – 7 = 6 2 13 12 - 1 7 3 6 9

Page 32: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Binary/Decimal numbers

2 3 2 - 1 7 3

Now the next column is 2 – 1 = 1.As before, 3 < 7, so we borrow one (which is 102=100)

from the next place left – it was 3, now becomes 2 13 – 7 = 6 2 13 12 - 1 7 3 1 6 9

Page 33: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Base 8 (octal) numbers

3 4 2 - 1 7 3

Starting at the right do 2-3.Can’t do that since 2 < 3, so we borrow one (which is

81 = 810 or 108) from the next place left. 128 – 38 = 78

3 3 12 - 1 7 3 7

Page 34: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Base 8 (octal) numbers

3 3 2 - 1 7 3

Now do 3 - 7. Borrow from the 82 place (64??)That is, borrow one from the leftmost position, making

the 3 into 2 and making the problem 138 – 78.

138 – 78 = 1110 – 710 = 4

3 13 12 - 1 7 3 4 7

Page 35: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Base 8 (octal) numbers

2 3 2 - 1 7 3

Now do 2 - 1. Still 2 – 1 = 1That’s it! the 3 into 2 and making the problem 138 – 78.

So 3428 - 1738 = 1478

3 13 12 - 1 7 3 1 4 7

Page 36: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Why Did We Do All Of That?

Because positional number systems like these prevail in most human systems, and in computers too.

In particular, we want to learn about binary (base 2) numbers because computers use binary to store all numbers, all data, all programs. Everything.

The last question asked about 11 slides ago was:

‘What Are Binary Numbers?’

Page 37: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Why Did We Do All Of That?

Binary allows electrical circuits to be simple. Lights, buzzers, toasters, TV sets can be on or off. Two states can be used easily to represent 2 digits:

0 = OFF 1 = ON.

So a number can be stored as the settings (states) of a set of switches:

0 1 1 0 0 1 0 = 50

Page 38: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Binary Numbers Are Everything

Everything on a computer is coded as numbers, and all numbers are binary.

Even commands for the computer to execute.

Computers have a memory, a circuit that does calculations, a circuit that controls overall operations, and lots of extra stuff for communications and long term storage.

Page 39: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Stored Program Computer

However:

Computers store the commands to be executed (the program) as numbers in its memory.

It fetches the next command (instruction) from memory, then executes it.

This is the fetch-execute cycle.

Page 40: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

4. Instructions are Binary Numbers

Principle 4 is:

All Computer Instructions are Binary Numbers.

Instructions in memory can be executed. Those not in memory have to be put there before they can be executed.

Page 41: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

4. Instructions are Binary Numbers

Why does this matter?

A good artist (or programmer I guess) needs to be able to have control over their computer.

To be a really good media artist you need to be able to make the machine do what you want (or at least have it make interesting errors)

Page 42: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Here is how the Fetch-execute cycle works

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

Here is a sample program in memory.

We’ll use decimal at first, and symbolic instructions.

Assume that we always start executing a program at memory location 0.

Page 43: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

The address of the instruction changes every time

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

It usually increases by 1.

We’ll use a special place to store the address of the next instruction, called theProgram counter.

It will initially contain 0.

000

Page 44: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

We also need a place where we can do the math

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

It’s like the display on a calculator.

We’ll call it the accumulator

We can add to is, load it, store it, take away from it, etc etc.

000

000

Page 45: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

We finally need a place to store the instruction

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

… because we increment the program counter.

We’ll call it the instruction register OK, now let’s execute.

000 000

PC IR ACC

Page 46: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

FETCH.

Get the instruction at the address indicated by the PC.Store it in the IRAdd 1 to the PC

000 000Load 004

PC IR ACC

Page 47: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

FETCH.

Get the instruction at the address indicated by the PC.Store it in the IRAdd 1 to the PC

001 000Load 004

PC IR ACC

Page 48: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

EXECUTE.

Execute the instruction in the IRIn this case, Load 4 means:‘Take the contents of memory location 4 and move a copy of it to the accumulator”

001 005Load 004

PC IR ACC

Page 49: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

FETCH.

Get the instruction at the address indicated by the PC.Store it in the IRAdd 1 to the PC

001 005Add 05

PC IR ACC

Page 50: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

FETCH.

Get the instruction at the address indicated by the PC.Store it in the IRAdd 1 to the PC

002 005Add 05

PC IR ACC

Page 51: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

EXECUTE.

Execute the instruction in the IRIn this case, Add 5 means:‘Take the contents of memory location 5 and add it to the accumulator”

002 014Add 05

PC IR ACC

Page 52: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

FETCH.

Get the instruction at the address indicated by the PC.Store it in the IRAdd 1 to the PC

002 014Store 06

PC IR ACC

Page 53: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

FETCH.

Get the instruction at the address indicated by the PC.Store it in the IRAdd 1 to the PC

003 014Store 06

PC IR ACC

Page 54: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

000

EXECUTE.

Execute the instruction in the IRIn this case, STORE 06 means:‘Take the contents of the accumulator and store it in memory location 6”

003 014Srore 06

PC IR ACC

Page 55: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

014

EXECUTE.

Execute the instruction in the IRIn this case, STORE 06 means:‘Take the contents of the accumulator and store it in memory location 6”

003 014Srore 06

PC IR ACC

Page 56: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

014

FETCH.

Get the instruction at the address indicated by the PC.Store it in the IRAdd 1 to the PC

003 014Halt

PC IR ACC

Page 57: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

014

FETCH.

Get the instruction at the address indicated by the PC.Store it in the IRAdd 1 to the PC

004 014005

PC IR ACC

Page 58: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

014

EXECUTE.

Execute the instruction in the IRIn this case, Halt means:‘Stop the computer; cease executing this program”

004 014005

PC IR ACC

Page 59: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

How a computer works - instructions

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

014

The program has completed.

This program was intended to add two numbers. Because we wrote it, we know where to find the answer: memory location 6

004 014005

PC IR ACC

Page 60: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Instructions are coded as numbers

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

014

Load is code 001 address is 8 bits so LOAD 4 is 001 00000100

001 00000100

Add 05

Store 06

HALT

005

009

014

Page 61: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Instructions are coded as numbers

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

014

Load is code 001 address is 8 bits so LOAD 4 is 001 00000100Add is code 101 address is 8 bits so ADD 5 is 101 00000101

000 0LOAD 001 1

010 2011 3100 4

ADD 101 5

001 00000100

101 00000101

Store 06

HALT

005

009

014

Page 62: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Instructions are coded as numbers

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

014

Add is code 101 address is 8 bits so ADD 5 is 101 00000101Store is code 010 address is 8 bits so Store 6 is 010 00000110

000 0LOAD 001 1STORE 010 2

011 3100 4

ADD 101 5

001 00000100

101 00000101010 00000110

HALT

005

009

014

Page 63: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Instructions are coded as numbers

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

014

Store is code 010 address is 8 bits so Store 6 is 010 00000110Halt is code 000 no address so Halt is 000 00000000

HALT 000 0LOAD 001 1STORE 010 2

011 3100 4

ADD 101 5

001 00000100

101 00000101010 00000110

000 00000000

005

009

014

Page 64: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Instructions are coded as numbers

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

014

Halt is code 000 no address so Halt is 000 00000000Data are simply stored as numbers

HALT 000 0LOAD 001 1STORE 010 2

011 3100 4

ADD 101 5

001 00000100

101 00000101010 00000110

000 00000000

000 00000101000 00001001

000 00001110

Page 65: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Instructions are coded as numbers

Load 04

Add 05

Store 06

000

001

002

003

004

005

006

007

008

009

010

HALT

005

009

014

There are many other instructions:BranchBranch on zero accumulatorNegateAnd

HALT 000 0LOAD 001 1STORE 010 2BZA 011 3BRA 100 4ADD 101 5NEG 110 6AND 111 7

001 00000100

101 00000101010 00000110

000 00000000

000 00000101000 00001001

000 00001110

Page 66: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Instructions are coded as numbers

HALT 000 0LOAD 001 1STORE 010 2BZA 011 3BRA 100 4ADD 101 5NEG 110 6AND 111 7

So, a computer program is really just a sequence

of numbers,

each of which

represents

a command or

instruction.

Page 67: How Computers Work … and how you can work them. Art 311 Lecture 04 Dr. J Parker

Next …

How can we represent things that don’t seem to be numbers?