Class Notes (835,629)
Canada (509,297)
EPSC 221 (6)

02Computer Structure.pdf

71 Pages
Unlock Document

Earth & Planetary Sciences
EPSC 221
Sonya Laszlo

Computer Structure Administrative Stuff  My office hours :  Monday 1:30-2:30  Wednesday 10:30-12:30  After class I can also chat for a bit  If times don't work please email.  McConnell Engineering Building Room 306  I'll post on WebCT if anything changes (e.g. sick, out of town, etc) Administrative Stuff  Course uses WebCT:  Grading scheme: 1 midterm (date TBA), assignments, and final exam  My email: [email protected] Last Class  Administrative issues / introduction  Introduction to what is a computer and what an algorithm is.  What makes programming hard and what makes a good programmer (patience and organization!)  A bit on the history of computers. Last Class  Recall that an algorithm is a description of how to solve (or do) a particular problem.  We are going to be learning to program in Fortran and C.  Whenever we write a program, we are in essence writing an algorithm for a computer to solve.  Later, we will look at more complicated algorithms that others have already written. This Class  How do computers store numbers?  What are some of the basics components of a computer  What is a compiler? How does it relate to a programming language? How does it relate to binary numbers?  Brief introduction to Fortran Why do we care?  Understand the reasons C/Fortran/other languages are designed as they were.  Help us develop a sense of what problems are easy to solve on a computer and what are more difficult.  Languages often designed to help make math convenient.  Also designed with hardware in mind. Storing something in a computer  How does a computer store data? It doesn't have a brain like we do.  Billions of wires which either have current flowing through them or don't have current flowing through them Example: Storing the result of a coin flip  We could decide to store a result of a coin flip by •1)Pick a particular switch in memory •2)If the flip was heads, send current through it •3)If the flip was tails, don't send current through it What if there were 3 choices?  If we had 3 possibilities, for example the result of a soccer match (win/loss/tie) we could choose TWO switches:   1)If both switches are “on” then “win”  2)If both switches are “off” then “loss”  3)If first switch is on and second is off then “tie”   We could choose a different assignment How many switches?  How many switches would we need to store the outcome of a roll of a die? (There are 6 options) Powers of two  Think about a dial based lock. If there are 2 digits which can all be 0 to 9, then there are 100 options. However, once I add a 3 digit which also has 10 possibilities there are 1000 options, 4 digit makes it 10,000, etc. The difference here is each “digit” has only 2 options.  This means each extra switch or digit DOUBLES the choices A more convenient notation  Writing “on” “off” all the time is cumbersome.  A simpler way to denote this is via 1 and 0  The digit 1 would mean “on”  The digit 0 would mean “off”  When we do this, it leads to the idea of binary numbers as a way to store a number in a computer Binary numbers  We are used to “base-10”  In “base-10,” every “column” has 10 choices (any number from 0-9)  Computers use “binary,” where there are only 2 choices (0 and 1) Analyzing base 10 6213 Looking more closely at the above nu, we can write it as 3 * 1 + 1 * 10 + 2 * 100 + 6 * 1000 where 1,10,100,1000 are powers of 10 i.e. 10^0, 10^1, 10^2, 10^3 Analyzing base 10 6213 However, instead of writing it as “sums of multiples of powers of 10” we can write it as “sums of multiples of powers of 2” (or 3,4,5,100,etc) Writing as powers of 2 6213 = 1*4096 + 1*2048 + 0*1024 + 0*512 + 0*256 + 0*128 + 1*64 + 0*32 + 0*16 + 0*8 + 1*4 + 0*2 + 1*1 4096 = 2^12 2048 = 2^11 1024 = 2^10 ... 1 = 2^0 In Binary 6213 = 1*4096 + 1*2048 + 0*1024 + 0*512 + 0*256 + 0*128 + 1*64 + 0*32 + 0*16 + 0*8 + 1*4 + 0*2 + 1*1 = 1100001000101 Base-2 (binary) vs Base-10 In base-2, each digit can be only a 0 or a 1. There is no such digit as 2 through 9 Each column counts as 2^0, 2^1, 2^2, etc instead of 10^0, 10^1, 10^2 etc So we have “ones” “twos” “fours” “eights” columns Nothing specific about base-2 except that it's convenient for thinking about computers (you can do the same thing to base-3, base-20, etc) A Computer Joke! (Groans)  There are 10 types of people in this world. Those that understand binary, and those that don't. Other bases: Base-16 (Hex) 6213 = 1*4096 + 8*256 + 4*16 + 5*1 = 1845 (in base-16) We only have 10 digits, so we use letters A-F when the coefficients are more than 9 Arithmetic in Binary Arithmetic in binary is done the same way as in base 10, except that we have to “carry” the digit whenever the sum is bigger than 1 (instead of whenever it is more than 9) 1 11 101 101 101 111 111 111 _____ _____ _____ 0 00 1100 Question: What sum did we just compute (in base 10)? Question to Ponder: In the same way that we adapted our ALGORITHM for base-10 addition to fit base-2 addition, how can we adapt the base-10 multiplication algorithm to multiply 2 binary numbers? What about division? Subtraction? One more (really) bad joke  Why do computer programmers get Halloween and Christmas confused?   (Hint: DEC means base 10 and OCT means base 8) One more (really) bad joke  Why do computer programmers get Halloween and Christmas confused?  Because OCT 31 = DEC 25 Why is this useful?  Since computers can only think in binary, if we were designing a computer that could add 2 numbers together, we'd need to put the circuitry together correctly to add using the base-2 algorithm—and not the base-10 one. Computer Architecture At the lowest level a computer is just a collection of switches that can be on or off (representing 1 and 0). The circuitry is organised into components that serve different functions such decoding bit sequences, carrying out simple arithmetic operations, etc. These switches also form the memory of the computer and can store the data being manipulated Von Neumann Machines Modern computers are called Von Neumann Machines John Von Neumann is credited with the idea that programs can be encoded and stored in the memory just like data A control unit transfers instructions from the memory into registers These instructions are executed and can access data stored in the memory The 5 Classic Components Computer CPU Memory Control Input Devices Registers Output Devices The Von Neumann Model  Programs and data are both stored in the main memory of the machine  There is one CPU (Central Processing Unit)  The CPU has a control unit that fetches program instructions from memory, decodes them and executes them The Von Neumann Model  Data is loaded from memory into registers in the CPU  The CPU contains circuitry to perform basic arithmetic operations and to compare values, placing the results into registers  The values in the registers can be stored in main memory The Von Neumann Model  Input devices (keyboard, pda, cell phone, . . .) allow us to place data (and programs) into memory  Output devices allow us to display values stored in memory (on screen, pda, cell phone, . . .) Low Level Programming Programmers in the late 1940’s had to use binary numbers to encode the instructions and the data the way the machine represented them (as switches) Very time consuming! Kind of thing that makes you become a raving lunatic! They call them PUNCH cards for a reason! Assembler The mnemonic names for machine instructions were developed into languages called assembly language Soon programs were written to convert these mnemonic symbols to binary sequences that could be loaded into the machine memory directly These programs are called assemblers Assembler Example Evaluate the expression f = (g + h) – (i + j) The first step is to use load instructions to transfer values stored in memory to registers g, h, i and j Load and Store instructions are part of the assembly language and allow transferring data values between memory and registers Assembler Example Evaluate the expression f = (g + h) – (i + j) Once the values are in registers g, h, i and j we can compute the result. Assembly program (where all the names refer to registers): add t0, g, h add t1, i, j sub f, t0, t1 Assembly Language  Low level language  Simple instructions of the form operation result, argument1, argument2  Because instructions are so simple and rigid, easy to translate into binary.  Still fairly tedious to write however.  Specific to individual machine Native Code An assembler translates this code into a binary sequence of instructions add t0, g, h -> 0110100000010010 add t1, i, j -> 0100100100110100 sub f, t0, t1 -> 0101010110001000 Loading the Program This binary sequ
More Less

Related notes for EPSC 221

Log In


Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.