1 / 61

How Computers Work

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.

damian
Download Presentation

How Computers Work

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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? • Thereare 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. Address Memory 1 0 1 2 3 4 5 6 7 8 9 10 2 4 8 16 32 64 128 256 512 1024

  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 • 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

  21. Binary/Decimal numbers • Why does the base have to be 10? It does not. • How about base 8? • 82 = 64 81 = 8 80=1 • So 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

  22. 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!

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

  25. Binary/Decimal numbers • 3 32 • - 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

  26. Binary/Decimal numbers • 2 32 • - 1 73 • 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

  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 81 = 810 or 108) from the next place left. • 128 – 38 = 78 • 3 3 12 • - 1 7 3 • 7

  28. Base 8 (octal) numbers • 3 32 • - 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

  29. Base 8 (octal) numbers • 2 32 • - 1 73 • Now do 2 - 1. Still 2 – 1 = 1 • That’s it! the 3 into 2 and making the problem 138 – 78. • So 3428 - 1738 = 1478 • 3 1312 • - 1 73 • 1 47

  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 • Load 04 • Here is how the Fetch-execute cycle works 000 001 002 003 004 005 006 007 008 009 010 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. • Add 05 • Store 06 • HALT 005 009 000

  37. How a computer works - instructions • Load 04 • The address of the instruction changes every time 000 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • 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.

  38. How a computer works - instructions • Load 04 • We also need a place where we can do the math 000 000 001 002 003 004 005 006 007 008 009 010 • Add 05 000 • Store 06 • 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.

  39. How a computer works - instructions • We finally need a place to store the instruction • Load 04 • PC IR ACC 000 000 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • HALT … because we increment the program counter. We’ll call it the instruction register OK, now let’s execute. 005 009 000

  40. How a computer works - instructions • Load 04 • PC IR ACC 000 Load 004 000 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • HALT FETCH. Get the instruction at the address indicated by the PC. Store it in the IR Add 1 to the PC 005 009 000

  41. How a computer works - instructions • Load 04 • PC IR ACC 001 Load 004 000 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • HALT FETCH. Get the instruction at the address indicated by the PC. Store it in the IR Add 1 to the PC 005 009 000

  42. How a computer works - instructions • Load 04 • PC IR ACC 001 Load 004 005 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • HALT 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” 005 009 000

  43. How a computer works - instructions • Load 04 • PC IR ACC 001 Add 05 005 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • HALT FETCH. Get the instruction at the address indicated by the PC. Store it in the IR Add 1 to the PC 005 009 000

  44. How a computer works - instructions • Load 04 • PC IR ACC 002 Add 05 005 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • HALT FETCH. Get the instruction at the address indicated by the PC. Store it in the IR Add 1 to the PC 005 009 000

  45. How a computer works - instructions • Load 04 • PC IR ACC 002 Add 05 014 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • HALT 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” 005 009 000

  46. How a computer works - instructions • Load 04 • PC IR ACC 002 Store 06 014 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • HALT FETCH. Get the instruction at the address indicated by the PC. Store it in the IR Add 1 to the PC 005 009 000

  47. How a computer works - instructions • Load 04 • PC IR ACC 003 Store 06 014 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • HALT FETCH. Get the instruction at the address indicated by the PC. Store it in the IR Add 1 to the PC 005 009 000

  48. How a computer works - instructions • Load 04 • PC IR ACC 003 Srore 06 014 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • HALT 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” 005 009 000

  49. How a computer works - instructions • Load 04 • PC IR ACC 003 Srore 06 014 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • HALT 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” 005 009 014

  50. How a computer works - instructions • Load 04 • PC IR ACC 003 Halt 014 000 001 002 003 004 005 006 007 008 009 010 • Add 05 • Store 06 • HALT FETCH. Get the instruction at the address indicated by the PC. Store it in the IR Add 1 to the PC 005 009 014

More Related