5/20/2008

Programming Announcements FIT100 FIT100 • Why is programming fun? • Undergraduate Research • Finally, there is the delight of working in such a Symposium tractable medium. The programmer, like the ∗ Friday poet, works only slightllihtly re-moved from pure thought-stuff. He builds his castles in the air, ∗ How many attended? from air, creating by exertion of the imagination. Few media of creation are so flexible, so easy to polish and rework, so readily capable of realizing grand conceptual structures. Source: Frederick P. Brooks, Jr. The Mythical Man-Month Essays on Software Engineering.

Announcements Announcements FIT100 FIT100 •Project 2B • Labs this week ∗ Due on Wednesday before 12 Noon ∗ Monday-Tuesday •If yyqou don't submit the quiz before 11, • Finish uppp pro ject 2B your answers are gone!! ∗ Wednesday-Thursday • Aim at submitting quiz before 11 • Grading spreadsheet that will calculate your current grade in the class

Getting Help Exercise 4 FIT100 FIT100 • JavaScript Exercise 4 ∗ Describe how you use a for loop to cyygcle through radio buttons to find the one that has been checked.

1 5/20/2008

Exercise 4 Exercise 4 FIT100 FIT100

name="animals" />

name="animals" />

name="animals" />

Exercise 4 Exercise 4 FIT100 FIT100

name="animals" />

name="animals" />

name="animals" />

Exercise 4 Exercise 4 FIT100 FIT100 for (var i = __; i < 3; i++) for (var i = __; i < 3; i++) { { if( ) if( ) { { //coding goes here //coding goes here } } } }

2 5/20/2008

Exercise 4 Exercise 4 FIT100 FIT100 for (var i = __; i < 3; i++) for (var i = __; i < 3; i++) { { if( ) if(document.getElementById ) { { //do something here } } } }

Exercise 4 Exercise 4 FIT100 FIT100 for (var i = __; i < 3; i++) for (var i = __; i < 3; i++) { { if(document.getElementById.checked ) if(document.getElementById.checked == true) { { //do something here //do something here } } } }

Instruction Execution FIT100 FIT100 Engines • What computers can do ∗ Perform or execute instructions to Following Instructions information • The computer must have instructions to follow

Principles of Computer Operation, or How Computers Work Short list!

9-18

3 5/20/2008

Instruction Execution Anatomy of a Computer FIT100 Engines FIT100 • What computers can't do • Computers have five basic parts or subsystems ∗ Have no imagination or creativity ∗ Memory, , arithmetic/logic unit ∗ Have no intuition (ALU), input unit, output unit ∗ Have no sense of irony, subtlety, proportion, decorum, or humor ∗ Are not vindictive or cruel ∗ Are not purposeful Long list! ∗ Have no free will ∗ Recent movies: Terminator, Matrix, AI

9-19 9-20

Byte-Size Memory FIT100 FIT100 Memory Location • Memory stores the program running and the • A commonly used diagram of computer data on which the program operates memory represents the discrete locations • Properties of memory: as boxes (1 byte each). • Address of location is displayed above ∗ Discrete locations—1 byte per location! the box. ∗ Addresses—For every memory location (byte) • whole numbers starting with zero • Value or contents of location is shown in the box. ∗ Values—Memory locations store values. ∗ Finite capacity—Limited size—data may not "fit" in the memory location.

9-21 • Overflow conditions, buffer overruns 9-22

Random Access Memory Memory (cont'd) FIT100 FIT100 (RAM) • 1-byte memory locations can store • "Random access" means the computer one ASCII character, or a number can refer to (access) the memory less than 256 (0 - 255) locations in any order • Often measured in • Programmers use a sequence of megabytes (MB) – millions of bytes or memory locations together, ignoring gigabytes (GB) – billions of bytes the fact that they all have different addresses • Large memory is preferable because there is more space for programs and ∗ Blocks of four bytes are used as a unit data (which usually equates to less I/O) so frequently that they are called 9-23 memory "words" 9-24

4 5/20/2008

Control Unit FIT100 FIT100 • Its circuitry fetches an instruction from memory, decodes the instruction, and fetches the operands used in it ∗ A typical instruction mi ght have the form ADD 4000, 2000, 2080 op dest, src1, src2 ∗ This instruction asks that the numbers stored in locations 2000 and 2080 be added together, and the result stored in location 4000 [4000] = [2000] + [2080] ∗ Data/Operand Fetch step must get these two values and after they are added, Result Return/Store step will store the answer in location 4000

9-25 9-26

Arithmetic/Logic Unit Input Unit and Output Unit FIT100 (ALU) FIT100 (I/O) • Performs the math • The wires and circuits through which ∗ A circuit in the ALU can add two numbers information moves into and out of a ∗ Other circuits do multiplication, comparisons, etc. computer •Instructijfions that just transfer data usually don't • Peripherals use the ALU ∗ Connect to the computer input/output ports. • Data/Operand Fetch step of the Cycle gets the values that the ALU needs to work on (operands) ∗ Not considered part of the computer, but specialized gadgets that encode or decode • After the ALU completes an operation, the information between the computer and the answer is moved from the ALU to the destination physical world. memory address specified in the instruction • Modems, monitors, scanners, printers, keyboard, 9-27 ∗ taxDue = taxRate[WA] * subtotal; 9-28 mouse, digitizing pad, mic, speakers

A Device Driver for The Peripherals FIT100 FIT100 Every Peripheral • Keyboard encodes keystrokes we type • "Dumb" devices provide basic physical into binary form for the computer translation to or from binary signals. • Monitor decodes information from the • Additional information from the computer computer's memory and displays it on a is needed to make it operate intelligently. lighted, colored screen • e.g., computer receives information that • Disks drives are used for both input and user typed shift and w at the same time. It output—storage devices where the converts to a capital W. The software that computer puts away information when it converts is called the device driver. is not needed, and can retrieve from when it is needed again 9-29 9-30

5 5/20/2008

The Program : Branch and The Pc's PC FIT100 FIT100 Jump Instructions • How does the computer determine which step • The instruction may include an to execute next? address to go to next. This changes • Address of the next instruction is stored in the the PC, so instead of going to PC +4 Control Unit in the (PC). automati call y, the comput er "jumps" • Because instructions use 4 bytes of memory, the next instruction must be at PC + 4, 4 bytes further or "branches" to the specified along in the sequence (in general). location. • Computer adds four to the PC, so when the F/E Cycle gets back to Instruction Fetch step, the PC is "pointing at" the next instruction.

9-31 9-32

Instruction Interpretation FIT100 FIT100 • Process of executing a program ∗ Computer is interpreting our commands, but in its own language • Before the F/E Cycle begins, some of the memory locations and the PC are visible in the control unit

9-33 9-34

The Fetch/Execute Cycle Animation FIT100 FIT100 • A five-step cycle: • Fetch/Execute Cycle 1. Instruction Fetch (IF) 2. Instruction Decode (ID) 3. Data Fetch (DF) / Operand Fetch (OF) 4. Instruction Execution (EX) 5. Result Return (RR) / Store (ST)

9-35

6 5/20/2008

How Important is Clock Cycling the F/E Cycle FIT100 FIT100 Speed? • Computers get their impressive • Modern computers try to start an instruction on capabilities by executing many of each clock tick • Pass off finishing instruction to other circuitry these simple (pipelining) • The Computer Clock: Determines ∗ Five instructions can be in process at the same time • Does a 1 GHz clock really execute a billion rate of F/E Cycle instructions per second? ∗ Measured in gigahertz (GHz), or billions ∗ Not a precise measurement. Computer may not be able to start an instruction on each tick, but may of cycles per second sometimes be able to start more than one instruction at a time

9-37 9-38

7