CS164 Computer Organization Study Guide

Key Concepts

  1. Computers generally consist of four major components:
    1. Central Processing Unit (CPU)
    2. Memory
    3. Input devices
    4. Output devices
  2. 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.
  3. I/O devices are often loosely grouped into two classes: storage devices and communications devices.
  4. The CPU is generally made up of several components:
    1. Arithmetic-Logic Unit (ALU)
    2. Registers
    3. Instruction Decoder
  5. 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.
  6. The CPU spends its life repetedly doing a simple procedure very fast:
    1. Send the contents of the PC out as a memory address.
    2. Read the contents of that memory location into the IR.
    3. Increment the PC.
    4. Determine what the instruction should do and sequence the transfer of data accordingly.
  7. The execution of an instruction breaks down into a series of simple steps. For example, the addition instruction might follow these steps:
    1. Transfer the contents of the accumulator to one input of the ALU.
    2. Send the operand out as a memory address.
    3. Take the data read from the specified memory location into the second input of the ALU.
    4. Instruct the ALU to perform an addition.
    5. Store the output from the ALU into the accumulator.
  8. 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.
  9. In almost every system, programs are loaded from an I/O device into memory and then control is transferred to the program.
  10. 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.
  11. 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.


  1. The CARDIAC CPU has exactly one general purpose register, called the accumulator.
  2. CARDIAC has only 10 instructions: INP, CLA, ADD, TAC, SFT, OUT, STO, SUB, JMP, and HRS.
  3. The last instrction to execute for any program should be the HRS.
  4. 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.
  5. 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.
  6. As a result, a bootable card deck for CARDIAC has four sections:
    1. Bootstrap loder: the cards 002 and 800
    2. The program to be loaded into memory: address-value card pairs
    3. The cards to transfer control to the program: e.g. the cards 002 and 810
    4. User input data for the program


Problem Statement

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 to itself.


Our approach to solving this problem will be as follows:

  1. Set product to 0.
  2. Input n.
  3. Input m.
  4. Subtract 1 from n.
  5. If n is negative jump to step 8.
  6. Add m to the product.
  7. Jump to step 4.
  8. Output the product.
  9. Halt.

Assembly Code

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
	SUB	00
	STO	n
	TAC	done	Step 5: If n is negative jump to step 8
	CLA	product	Step 6: Add m to the product
	ADD	m
	STO	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 it. 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 multiply. If, for example, we want to multiply 23 by 5, we can use the deck:


What to exepect on the exam

  1. For any questions related to the CARDIAC, we will give you the opcode table that shows which opcodes correspond with which assembly language mnemonics.
  2. 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.
  3. The exam may reinforce some things you had to learn about the CARDIAC when doing your lab assignment.
  4. 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 be CARDIAC-specific.