CS164 Computer Organization Study Guide
- Computers generally consist of four major components:
- Central Processing Unit (CPU)
- Input devices
- Output devices
- Memory is a large collection of locations, each identified
by an address.
Each memory location stores exactly one number.
Electronically, those numbers are stored in binary notation.
In most computers, we think about the number in binary, octal, or
hexadecimal, but in the CARDIAC, we think about them in decimal.
- I/O devices are often loosely grouped into two classes: storage devices
and communications devices.
- The CPU is generally made up of several components:
- Arithmetic-Logic Unit (ALU)
- Instruction Decoder
- Each register in the CPU stores one number, like memory locations do.
Some registers are directly accessible to the program, and others are not.
Most CPUs have one or more general purpose registers, a program counter,
and an instruction register.
- The CPU spends its life repetedly doing a simple procedure very fast:
- Send the contents of the PC out as a memory address.
- Read the contents of that memory location into the IR.
- Increment the PC.
- Determine what the instruction should do and sequence the transfer of data accordingly.
- The execution of an instruction breaks down into a series of
For example, the addition instruction might follow these steps:
- Transfer the contents of the accumulator to one input of the ALU.
- Send the operand out as a memory address.
- Take the data read from the specified memory location into
the second input of the ALU.
- Instruct the ALU to perform an addition.
- Store the output from the ALU into the accumulator.
- Every computer program is ultimately running as (or running on)
a series of machine language instructions.
Although most real machine languages are much more complex than the
CARDIAC we used as an example, they pretty much all have mechansisms
for loading and storing registers, adding and subtracting, conditional
jumps, and jumps that save the program counter for later use.
Furthermore, the complexities of the more realistic systems can
be built from the simpler capabilities of machines like the CARDIAC.
- In almost every system, programs are loaded from an I/O
device into memory and then control is transferred to the program.
- Programs must take some action to indicate that they are finished
running and that the computer should halt or control should be turned
over to some other program.
- Numbers are just numbers.
A number inside a computer has no inherent meaning or type.
The number 123 might be the number of people in a class, or
the fraction 0.123 giving the weight of a homework assignment,
or the CLA 23 instruction on the CARDIAC.
Which of these depends on how its used.
If the number is read from an input card on the CARDIAC, it is
a data item to be stored in memory.
If it's loaded into the instruction register, it will be interpreted
as an instruction for the CPU to follow.
- The CARDIAC CPU has exactly one general purpose register,
called the accumulator.
- CARDIAC has only 10 instructions: INP, CLA, ADD, TAC, SFT,
OUT, STO, SUB, JMP, and HRS.
- The last instrction to execute for any program should be the HRS.
- CARDIAC has only one input device and one output device.
These devices are a card reader and a card punch (writer).
Each card stores a single number.
So each INP instruction reads one number from the set (deck) of input
cards and stores that number into memory.
Likewise, each OUT instruction takes one number from memory,
puts it onto a card, and adds that card to the output set.
- Because the cards are the only input device, they have to serve
both as the storage device from which a program gets loaded
into memory and as the source of user input to a running program.
- As a result, a bootable card deck for CARDIAC has four sections:
- Bootstrap loder: the cards 002 and 800
- The program to be loaded into memory: address-value card pairs
- The cards to transfer control to the program: e.g. the cards 002 and 810
- User input data for the program
We will take two numbers from the input and, by repeated addition,
multiply them together.
We'll take the first number as the number of times to add the second
Our approach to solving this problem will be as follows:
- Set product to 0.
- Input n.
- Input m.
- Subtract 1 from n.
- If n is negative jump to step 8.
- Add m to the product.
- Jump to step 4.
- Output the product.
In the following assembly language code, we'll label the algorithm
steps in the comment area.
product DATA 000 Step 1: Set product to 0
n DATA 000
m DATA 000
start INP n Step 2: Input n
INP m Step 3: Input m
loop CLA n Step 4: Subtract 1 from n
TAC done Step 5: If n is negative jump to step 8
CLA product Step 6: Add m to the product
JMP loop Step 7: Jump to step 4
done OUT product Step 8: Output the product
HRS 00 Step 9: Halt
Now, we'll turn the assembly language into machine language.
We'll put the data items at locations 04, 05, and 06, and we'll start
the program code at location 10.
04 000 product DATA 000 Step 1: Set product to 0
05 000 n DATA 000
06 000 m DATA 000
10 005 start INP n Step 2: Input n
11 006 INP m Step 3: Input m
12 105 loop CLA n Step 4: Subtract 1 from n
13 700 SUB 00
14 605 STO n
15 320 TAC done Step 5: If n is negative jump to step 8
16 104 CLA product Step 6: Add m to the product
17 206 ADD m
18 604 STO product
19 812 JMP loop Step 7: Jump to step 4
20 504 done OUT product Step 8: Output the product
21 900 HRS 00 Step 9: Halt
Creating the Bootable Deck
Now that we have the machine language code in place, we can
create the set of input cards that will load the program and run
The first to cards will be the standard 002, 800 bootstrap loader.
Then we'll have cards for each of the machine language instructions
in our program as well as for the product variable.
For each of these, we'll have two cards, an address and a value.
So for the TAC instruction at location 15, for example, we'll have
the cards 015 and 320.
After those, we'll have the cards that start running our program:
002 and 810.
Finally, we'll have a card for each of the two numbers we want to
If, for example, we want to multiply 23 by 5, we can use the deck:
What to exepect on the exam
- For any questions related to the CARDIAC, we will give you
the opcode table that shows which opcodes correspond with
which assembly language mnemonics.
- Because of time constraints, don't expect to be asked to
write a program for the CARDIAC that is as extensive as the
one in your lab.
- The exam may reinforce some things you had to learn about
the CARDIAC when doing your lab assignment.
- Although much of the focus was on the CARDIAC as an
example of a computer design, it was just an example.
The exam may well include questions that focus on the basic
concepts of how computers work as well as some that might