CPSC 100, Spring 1997:
Answers to Quiz #3

This is the third quiz from the course Computer Science 100: Principles of Computer Science, taught by David Eck. The answers that are included here are sample answers only. There might be many other answers to a given problem that would also receive full credit. See the home page for the text, The Most Complex Machine, for more information about the course.

Question 1: The terms location and address are related to a computer's main memory (or RAM). Explain these two terms. What is the difference between them?

Answer: The RAM consists of a sequence of locations. Each location is a memory unit that can hold a binary number. The locations are numbered sequentially, and the number that corresponds to a particular location is called the address of that location. Thus, locations are actual, physical spots in memory, and address are numbers that are used to pick particular locations out of all the possible locations.

Note: On the xComputer model computer, there are 1024 locations, and an address is a number between 0 and 1023. Each location on the xComputer holds a 16-bit binary number. However, the number of locations in memory and the size of the binary numbers that they hold vary from computer to computer. (This question was really a question about computers in general, not just about the xComputer.)

Question 2: Explain the difference between the instructions "ADD 42" and "ADD-C 42".

Answer: Each of these instructions tells the CPU to add a number to the value that is already stored in the accumulater and to put the resulting sum back into the accumulator. However, for the ADD 42 instruction, the number to be added is whatever happens to be stored in memory location number 42. For the ADD-C 42 instruction, on the other hand, the number to be added in the number 42 itself.

Question 3: The clock in xCompter does not keep time. What role does it play?

Answer: The clocs "ticks" by turning an output wire on and off. Each time this wire is turned on and off, one step of the fetch-and-execute cycle is performed. Thus, the ticking of the clock drives the whole operation of the CPU.

Note: The clock in xComputer also has a control wire named Stop-Clock. When this wire is off, the clock ticks and the computer runs; when it is on, the clock does not tick so the computer is not operating. But this doens't mean that the main purpose of the clock is to turn the computer on and off!

Question 4: Every fetch-and-execute cycle in xComputer begins with the same three substeps. State the purpose of doing each of these steps. (Why is the step necessary?)

  1. Load-ADDR-from-PC (that is, copy the contents of the program counter register into the address register).
  2. Load-IR-from-memory (that is, copy the number on memory's data-out wires into the instruction register).
  3. Increment-PC (that is, add one to the value in the program counter register).

Answer: At the beginning of the fetch-and-execute cycle, the address of the next instruction in memory is stored in the program counter register. The computer must fetch that instruction from the specified address, execute that instruction, and then -- in the next fetch-and-execute cycle -- go on to the next instruction. These first three steps of the cycle do the following:

  1. Load-ADDR-from-PC: The ADDR register is connected to the address wires of the main memory. Putting a value in this register tells the main memory which location to use. Since the PC contained the address of the next instruction to be executed, the main memory is now set to deliver that instruction.
  2. Load-IR-from-memory: Once the address has been set by the previous step, the instruction that is stored in the specified location appears on the memory's data-out wires. This step copies that instruction into the instruction register in the CPU. (This instruction will be executed by later stages in this fetch-and-execute cycle.)
  3. Increment-PC: After the current cycle ends, the CPU will go on to the next instruction in the program. The PC must be set up to contain the addess of that instruction. Ordinarily, the next program instruction is in the next memory location, so adding 1 to the value in the PC gets it ready with the location of the instruction for the next fetch-and-execute cycle. (Note however, that the value in the PC might still be changed before that cycle begins, if the instruction that is being executed in this cycle is a jump instruction.)

David Eck, 24 April 1997