Date post: | 02-Jan-2016 |
Category: |
Documents |
Upload: | alannah-clark |
View: | 215 times |
Download: | 0 times |
How Computers Work
… and how you can work them.
Art 315 Lecture 03
Dr. J Parker
Fall 2010
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)
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
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.
ASCII
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.
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
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.
1248
163264
128256512
1024
012345678910
Address Memory
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
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!)
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?
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)
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’)
Electricity
For electricity to flow there needs to be a complete loop (unlike water)
Flow is from negative to positive.
Complete loop is a conductor from the –ve pole of the source of electricity to the +ve.
+- Arrows show the direction
Of electron motion.
Electricity
For electricity to flow there needs to be a complete loop (unlike water)
That’s why a switch can turn off a light – it breaks the circuit and there is no longer a loop.
+- Arrows show the direction
Of electron motion (or not).
Electricity
So how can we represent numbers?
Hmm, 10 digits. Maybe 10 voltages? Leads to complex and slow circuits.
ENIAC
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?
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
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
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
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!
Binary/Decimal numbers
We can do math in much the same way irrespective of base.
Listen carefully:
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
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
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
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
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
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
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?’
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
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.
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.
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.
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)
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
Next …
How can we represent things that don’t seem to be numbers?