MCS-170 The Nature of Computer Science
1. Review: Von Neumann Architecture (Chapter 14)
- A computer consists of three main elements:
- Memory (storage
for data and
- I/O devices (allows
user to input data and instructions, and
These three are connected by buses - collections of wire over which
data flows (look at actual inside buses of a computer)
The Von Neumann
architecture. Directed lines represent
buses and the
flow of information between the computer components.
2. CPU - The "Brains" of a Computer
- Tasks of a CPU:
- fetches instructions and data from memory
- executes instructions
- stores results back in memory
- CPU subunits
Logic Unit (ALU): circuitry that performs operations
such as addition
- Registers: fast memory units built into the
Unit: circuitry that fetches data and instructions from
main memory as
well as controlling the flow of data between ALU and registers
(overhead - Reed, Fig. 14.1)
- Real Example from Motorola
- CPU datapath
- Path that data follows within CPU along the buses from
registers to the ALU and back
- A single rotation around the CPU datapath is called the CPU
- To better understand how a CPU works, we use a simple model
of a CPU in the lab -- one with 4 registers and an
ALU (with operations for addition, subtraction, bitwise-AND, and
bitwise-OR). This simplfied CPU does not have a Control
Unit. Instead, we act as the control unit, selecting the input
registers, ALU function, and
output register by clicking on the appropriate knobs.
- CPU Cycle
-- A single rotation around the datapath: Registers -> ALU -> Registers
Each instruction takes one CPU cycle.
But, not all computers share the same set of basic instructions. For
example, Computer A might take two cycles to fetch a piece of
data from memory, whereas Computer B might take four cycles.
So, 800 MHz CPU is not necessarily slower than a 1.0 GHz (=1000 MHz)
computer. It depends on the basic instruction sets for the two
computers and how many cycles instructions take.
3. Datapath and Memory
- Above example just concentrates on what happens in the CPU. But,
a computer also needs to access memory.
- Main Memory (RAM - Random
Access Memory) stores all of the programs, data, etc, that CPU needs to
operate on. Instructions and Data need to be brought into CPU datapath
and then results put back into main memory.
- Memory is a list of locations, each with an address --
a number that uniquely defines the memory location.
- Memory bus connects CPU to Main Memory, CPU can move data from
a memory location into one of its registers, and move data from a
register back to main memory.
Overhead - Fig. 14.6 from Reed
- Example -- We have 2
numbers that we want to add - assume these
are stored at memory locations 10, 11 in main memory. To add the
numbers and put the result in memory location 12, we must:
- 1. Initialize R0 on CPU to be 0 (We will store
- 2. For each number stored at memory locations 10, 11 we need to:
- Copy the number from memory to a register, say R1 (This
will take several CPU cycles to accomplish!)
- In one CPU cycle, compute R0+R1 and put the result back in R0.
When we finish with the number at
memory location 11, we have
the sum stored in R0.
- 3. Move the result to memory location 12. (Again, this will
take several CPU cycles).
- PseudoCode for this
- 1. R0 = 0
- R0 = R0 + R1
- R1 = M
- R0 = R0 + R1
- 3. M = R0
- (In Class) Describe the process one would use to sum a list of 4
numbers, stored at locations 10-13 in main memory. (Write out on paper
a process in Pseudocode as we did above)