Presentation is loading. Please wait.

Presentation is loading. Please wait.

How Computers Work … and how you can work them. Art 315 Lecture 03 Dr. J Parker Fall 2010.

Similar presentations


Presentation on theme: "How Computers Work … and how you can work them. Art 315 Lecture 03 Dr. J Parker Fall 2010."— Presentation transcript:

1 How Computers Work … and how you can work them. Art 315 Lecture 03 Dr. J Parker Fall 2010

2 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)

3 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

4 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.

5 ASCII

6 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.

7 Computers can only manipulate numbers. Computers can do the following things to numbers: Add them (and subtract) Store in memory Get from memory Some can multiply/divide Logical: AND, OR, NOT etc

8 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.

9 1 2 4 8 16 32 64 128 256 512 1024 0 1 2 3 4 5 6 7 8 9 10 Address Memory

10 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

11 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!)

12 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?

13 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)

14 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’)

15 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.

16 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).

17 Electricity So how can we represent numbers? Hmm, 10 digits. Maybe 10 voltages? Leads to complex and slow circuits. ENIAC

18 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?

19 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

20 Binary/Decimal numbers The number 342 in base 10 is really 3 x 100 + 4 x10 + 2 or 3x10 2 + 4x10 1 + 2x10 0 The exponent is the digit position, counted right to left starting at 0. Position 3 2 1 0 10 3 =1000 10 2 =100 10 1 =10 10 0 =1 x x x x 0 3 4 2 300 + 40 + 2 = 342 173 = 100 + 70 + 3 = 1x10 2 + 7x10 1 + 3x10 0

21 Binary/Decimal numbers Why does the base have to be 10? It does not. How about base 8? 8 2 = 64 8 1 = 8 8 0 =1 So 342 in base 8 is: 3x8 2 + 4x8 1 + 2x8 0 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 342 10 342 base 8 is 342 8

22 Binary/Decimal numbers Numbers always represent the same things so 12 10 means this many: | | | | | | | | | | | | 14 8 = 12 10 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!

23 Binary/Decimal numbers We can do math in much the same way irrespective of base. Listen carefully:

24 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 10 1 = 10) from the next place left. 12 – 3 = 9 3 3 1 2 - 1 7 3 9

25 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 10 2 =100) from the next place left – it was 3, now becomes 2 13 – 7 = 6 2 1 3 1 2 - 1 7 3 6 9

26 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 10 2 =100) from the next place left – it was 3, now becomes 2 13 – 7 = 6 2 1 3 1 2 - 1 7 3 1 6 9

27 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 8 1 = 8 10 or 10 8 ) from the next place left. 12 8 – 3 8 = 7 8 3 3 1 2 - 1 7 3 7

28 Base 8 (octal) numbers 3 3 2 - 1 7 3 Now do 3 - 7. Borrow from the 8 2 place (64??) That is, borrow one from the leftmost position, making the 3 into 2 and making the problem 13 8 – 7 8. 13 8 – 7 8 = 11 10 – 7 10 = 4 3 1 3 1 2 - 1 7 3 4 7

29 Base 8 (octal) numbers 2 3 2 - 1 7 3 Now do 2 - 1. Still 2 – 1 = 1 That’s it! the 3 into 2 and making the problem 13 8 – 7 8. So 342 8 - 173 8 = 147 8 3 1 3 1 2 - 1 7 3 1 4 7

30 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?’

31 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

32 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.

33 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.

34 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.

35 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)

36 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.

37 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 the Program counter. It will initially contain 0. 000

38 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

39 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 PC IR ACC

40 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 IR Add 1 to the PC 000 Load 004 PC IR ACC

41 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 IR Add 1 to the PC 001000Load 004 PC IR ACC

42 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 IR In this case, Load 4 means: ‘Take the contents of memory location 4 and move a copy of it to the accumulator” 001005Load 004 PC IR ACC

43 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 IR Add 1 to the PC 001005Add 05 PC IR ACC

44 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 IR Add 1 to the PC 002005Add 05 PC IR ACC

45 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 IR In this case, Add 5 means: ‘Take the contents of memory location 5 and add it to the accumulator” 002014Add 05 PC IR ACC

46 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 IR Add 1 to the PC 002014Store 06 PC IR ACC

47 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 IR Add 1 to the PC 003014Store 06 PC IR ACC

48 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 IR In this case, STORE 06 means: ‘Take the contents of the accumulator and store it in memory location 6” 003014Srore 06 PC IR ACC

49 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 IR In this case, STORE 06 means: ‘Take the contents of the accumulator and store it in memory location 6” 003014Srore 06 PC IR ACC

50 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 IR Add 1 to the PC 003014Halt PC IR ACC

51 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 IR Add 1 to the PC 004014005 PC IR ACC

52 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 IR In this case, Halt means: ‘Stop the computer; cease executing this program” 004014005 PC IR ACC

53 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 004014005 PC IR ACC

54 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

55 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 Add is code 101 address is 8 bits so ADD 5 is 101 00000101 000 0 LOAD001 1 010 2 011 3 100 4 ADD101 5 001 00000100 101 00000101 Store 06 HALT 005 009 014

56 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 00000101 Store is code 010 address is 8 bits so Store 6 is 010 00000110 000 0 LOAD001 1 STORE010 2 011 3 100 4 ADD101 5 001 00000100 101 00000101 010 00000110 HALT 005 009 014

57 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 00000110 Halt is code 000 no address so Halt is 000 00000000 HALT000 0 LOAD001 1 STORE010 2 011 3 100 4 ADD101 5 001 00000100 101 00000101 010 00000110 000 00000000 005 009 014

58 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 00000000 Data are simply stored as numbers HALT000 0 LOAD001 1 STORE010 2 011 3 100 4 ADD101 5 001 00000100 101 00000101 010 00000110 000 00000000 000 00000101 000 00001001 000 00001110

59 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: Branch Branch on zero accumulator Negate And HALT000 0 LOAD001 1 STORE010 2 BZA011 3 BRA100 4 ADD101 5 NEG110 6 AND111 7 001 00000100 101 00000101 010 00000110 000 00000000 000 00000101 000 00001001 000 00001110

60 Instructions are coded as numbers HALT000 0 LOAD001 1 STORE010 2 BZA011 3 BRA100 4 ADD101 5 NEG110 6 AND111 7 So, a computer program is really just a sequence of numbers, each of which represents a command or instruction.

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


Download ppt "How Computers Work … and how you can work them. Art 315 Lecture 03 Dr. J Parker Fall 2010."

Similar presentations


Ads by Google