Title: CS 177 Week 13 Recitation Slides
1CS 177 Week 13 Recitation Slides
Inside The Von Neumann Computer
2Announcements
- REMINDER Project 4 due Wednesday Dec 3rd right
after Thanksgiving Break. Plan accordingly! - Evening consultant hours next week on Monday and
Tuesday only (Tuesday will only have one TA
present) - Final recitation sessions will be the week before
finals - Review of course material
- Recitation evaluations will be completed
3Project 4 Item Drop Down Menu
- Some students are confused by how to set up the
drop down menu to select the course. - Below, you will find the code you should use to
create the drop down menu for project 4
ltselect id"course" size"4" onchange"choose_cour
se()"gt ltoption value"1" selectedgtCS 177
Programming with Multimedia Objectslt/optiongtÂ
ltoption value"2"gtCS 180 Programming Ilt/optiongtÂ
ltoption value"3"gtCS 110 Introduction to
Computerslt/optiongt ltoption value"4"gtCS 182
Foundations of Computer Sciencelt/optiongtlt/selectgt
4Project 4 Item For Loops
- Some students were confused when seeing a for
loop used in step 8 of the project spec since we
only covered while loops in the course. - For loops are an alternative to while loops that
can be used in the same way but are coded with
different syntax - The general form of a for loop is as follows
FOR (INITIALIZATION BOOLEAN_TEST UPDATE)
STATEMENTS_EXECUTED_AS_LONG_AS_TRUE
- Initialization set default value for variables
or counters - Boolean_test same as in the while loop. Loop
will execute as long as this test results in
true - Update update variables or counters to prevent
infinite loops.
5For Loop vs. While Loop
- Observe the following example for how to
implement a simple loop to print all numbers
between 1 and 10 inclusive
For loop
While loop
- var count 1
- while (count lt 10)
- document.write(Count is count)
- count
-
- for (var count 1 countlt10 count)
- document.write(Count is count)
-
- Note how the for loop achieves the same
functionality with less code
6Project 4 Item Dynamic Table
- Many students have noted that the dynamic table
for project 4 cannot be created in the same way
as in project 2. Particularly, how can you add
columns dynamically to the table when we do not
know how many we will need in advance? - Lets say you want to create the top row in the
table with the items to be graded in the
specified course. The following code will achieve
this
table document.getElementById("table_id") new_r
ow table.insertRow(0) new_row.innerHTML
lttdgtlt/tdgt var num0 while (num lt
itemsArray.length) new_row.innerHTML
lttdgtitemsArraynumlt/tdgt num
7 8CPU Subunits and Datapath
- What is the CPU?
- Brain of the computer
- Executes instruction obtained from memory and
writes results back to memory - Program instructions are in the machine language
of that CPU - High-level instructions must be translated into
machine language before executing
von Neumann architecture
9CPU Subunits
- Arithmetic Logic Unit (ALU) performs the
operations on data (addition, subtraction, bit
manipulations) - Registers memory locations built into the CPU
- data transferred between registers and main
memory via a bus - Control Unit (CU) circuitry in charge of
fetching data and instructions from main memory,
as well as controlling the flow of data between
registers and the ALU
10CPU Datapath Cycles
- Datapath - path that data follows within the CPU,
traveling along buses from registers to the ALU
and then back to registers - Datapath cycle - a single rotation around the
CPU datapath - CPU speed - the number of CPU cycles per second
- e.g.., a 3.0GHz CPU can perform 3.0 billion
cycles per second - Not all computers are created equal!
- CPUs have different instruction sets and one may
be able to complete more complex tasks in a
single cycle - so, a slower CPU with a richer instruction set
may complete some tasks faster
11CPU and Main Memory
- CPU is connected to the computers main memory
via a bus - main memory is comprised of a large number of
memory locations accessed by its address - main memory stores all active programs and data
- data and instructions are copied to registers and
the results are then copied back to main memory
12Main Memory Data Transfer
- Control unit processes program instructions and
identifies data needed to carry out tasks - Data is then fetched from main memory along the
main memory bus and copied into registers. This
MUST occur before the data can be operated on by
the ALU - The data transfer takes much longer than a single
datapath cycle due to the distance that must be
covered - Modern CPUs compensate by fetching multiple
instructions at once
13Stored-Program Computer
- A stored-program computer allows tasks to be
represented as instructions stored in main memory
along with data - control unit fetches, decodes, and executes those
instructions - Each CPU has its own machine language
instructions represented as binary strings where
the bits correspond to hardware settings - These encoded instructions will tell the computer
what simple commands to execute on the data (e.g.
add, subtract, load etc) - Why is this approach better than the previous
examples?
14Examples of Machine Language Instructions
- 1st two instructions select ALU operation and
registers to operate on - Next 3 instructions control flow of data
between main memory and datapath - Last instruction mark the end of instruction
sequence
15Fetch-Execute Algorithm
- Essentially the algorithm can be broken down into
the following steps - Control unit fetches machine language
instructions from memory - It then decode the instruction and interprets its
meaning - Next it executes the required CPU datapath cycle,
- Finally, it moves on to the next instruction and
repeats the previous steps
16Fetch-Execute Algorithm
- In the above algorithm, how does the control unit
know when the sequence of instructions is over? - The HALT instruction indicates end of sequence
- How does the control unit know in a real
computer? - The operating system is responsible for keeping
track of the programs location
17The Role of I/O Devices
- I/O devices enable the user to interact with the
computer - For the first programmable computers, the user
triggered the single programs execution - User entered program instructions and data into
main memory via input devices - User instructed the CPU to fetch program
instructions and execute them in sequential order - User viewed results by sending the contents of
the memory to an output device - Most modern computers allow for multitasking
- separate portions of main memory for program
instructions and data - during program switches, CPU must save the state
of the current program and locate the portion of
memory for the new program (handled by OS)
18Machine vs. Assembly Language
- machine code is nearly impossible to understand
and debug (difficult to program) - assembly languages simplify programming
- assembly languages allow for words to substitute
for bit patterns - also, allow for variable names instead of
numerical addresses
19QUESTIONS???