14.1
A Balanced Introduction to Computer Science, 3/E
David Reed ©Pearson Prentice Hall, 2011
Chapter 14 Review Question Solutions
14.1. What would happen if you placed the number 100 in R0, then set the knobs so that A
Bus = R0, B Bus = R0, ALU = A-B, and C Bus = R0?
The value in Register 0 would be subtracted from itself and the result, 0, stored back
into Register 0.
14.2. Describe the settings that would cause the value stored in R2 to be doubled.
A Bus = R2, B Bus = R2, ALU = A+B, and C Bus = R2.
14.3. How many cycles are required to add the contents of R0, R1, and R2 and then place
the sum in R3? Describe the settings for each cycle.
A Bus = R0, B Bus = R1, ALU = A+B, C Bus = R3.
A Bus = R2, B Bus = R3, ALU = A+B, C Bus = R3.
14.4. What settings would result in the sum of registers R0 and R3 being stored in memory
location 4?
A Bus = R0, B Bus = R3, ALU = A+B, C Bus connected to MM, R/W = 4.
14.5. What settings would cause the contents of memory address 4 to be copied into
register R0?
MM Bus connected to C, C Bus = R0, R/W = 4.
14.6. Assuming that data can be copied to and from main memory in a single CPU cycle,
how many cycles are required to add the contents of memory addresses 5 and 6 and
then store the result in memory address 7? Describe the settings for each cycle.
MM Bus connected to C, C Bus = R0, R/W = 5.
MM Bus connected to C, C Bus = R1, R/W = 6.
A Bus = R0, B Bus = R1, ALU = A+B, C Bus connected to MM, R/W = 7.
14.7. What task would the following machine-language program perform?
0: 1010001000000000
1: 1000001000000011
14.2
2: 1111111111111111
This program stores the value 0 in memory address 3. The first statement subtracts
the value in R0 from itself, and stores the result (0) back in R0. The second statement
stores the value from R0 in MM[3]. The third statement halts execution.
14.8. What sequence of machine-language instructions would cause the contents of the four
registers to be copied into memory locations 7, 8, 9, and 10, respectively?
1000001000000111
1000001000101000
1000001001001001
1000001001101010
1111111111111111
14.9. What sequence of machine-language instructions would cause the simulator to add
the contents of memory locations 10, 11, and 12 and then store the result in memory
location 13?
1000000100001010
1000000100101011
1000000101001100
1010000100110001
1010000100111011
1000001001101101
1111111111111111
14.10. What do you think would happen if you forgot to place a HALT instruction at the end
of a machine-language program? How would the Control Unit react? Use the
simulator to test your prediction, then report the results.
The Program Counter would advance beyond the last instruction. The contents of
memory addresses would be treated as instruction codes, either producing unexpected
results or an error if the code does not correspond to a legal instruction.
14.11. What sequence of assembly-language instructions corresponds to the machinelanguage
instruction set from Exercise 14.7?
SUB R0 R0 R0
STORE 3 R0
HALT
14.12. What sequence of assembly-language instructions corresponds to the machinelanguage
instruction set you wrote in Exercise 14.9?
LOAD R0 10
LOAD R1 11
LOAD R2 12
14.3
ADD R3 R0 R1
ADD R3 R2 R3
STORE 13 R3
HALT
14.13. Write a sequence of assembly-language instructions that multiplies the contents of
memory location 10 by four. For example, if the number 10 were stored in memory
location 10, executing your instructions would cause the simulator to store 40 there.
Note: although the ALU Operation knob does not provide a multiplication setting, a
number can be multiplied via repeated additions (e.g., 10* 4 = 10+10+10+10).
LOAD R0 10
ADD R0 R0 R0
ADD R0 R0 R0
STORE 10 R0
HALT
1. TRUE or FALSE? Any piece of memory that is used to store the sum of numeric values
is known as a register.
FALSE
2. TRUE or FALSE? The path that data follows within the CPU, traveling along buses
from registers to the ALU and then back to registers, is known as the CPU datapath.
TRUE
3. TRUE or FALSE? All modern CPUs provide the same set of basic operations that can be
executed in a single CPU cycle.
FALSE
4. TRUE or FALSE? The size of main memory is generally measured in MHz or GHz.
FALSE
5. TRUE or FALSE? Suppose you wish to add two numbers that are stored in memory.
Before the Arithmetic Logic Unit (ALU) can add the numbers, they must first be
transferred to registers within the CPU.
TRUE
14.4
6. TRUE or FALSE? In real computers, it takes roughly the same amount of time to
transfer data from main memory to registers as it does to add two numbers in registers.
FALSE
7. TRUE or FALSE? Within the CPU, the Control Unit is responsible for fetching
machine-language instructions from memory, interpreting their meaning, and carrying
out the specified CPU cycles.
TRUE
8. TRUE or FALSE? Suppose a CPU contains eight registers. Within a machine-language
instruction, at least three bits would be required to uniquely identify one of the registers.
TRUE
9. TRUE or FALSE? In a multitasking computer, the program counter keeps track of how
many programs are currently loaded into main memory.
FALSE
10. TRUE or FALSE? In a stored-program computer, both machine-language instructions
and the data operated on by those instructions can reside in main memory at the same
time.
FALSE
11. Name the three subunits of the CPU, and describe the role of each subunit in carrying out
computations.
The arithmetic logic unit (ALU) is the collection of circuitry that performs actual
operations on data. Registers are memory locations that are built into the CPU and
accessed directly by the ALU. The control unit is the circuitry in charge of fetching data
and instructions from main memory, as well as controlling the flow of data from the
registers to the ALU and back to the registers.
12. Describe how data values move around the CPU datapath and what actions occur during
a single CPU cycle. How does the datapath relate to CPU speed?
The path that data follows within the CPU, traveling along buses from registers to the
ALU and then back to registers, is known as the CPU datapath. Every task performed by
a computer, from formatting a document to displaying a page in a Web browser, is
broken down into sequences of simple operations; the computer executes each individual
operation by moving data from the registers to the ALU, performing computations on that
14.5
data within the ALU, and then storing the result in the registers. CPU speed measure
how many such cycles occur in one second, e.g., 1.8 GHz means 1.8 billion CPU cycles
per second.
13. Consider two computer systems that are identical except for their CPUs. System 1
contains a 1.8 GHz Pentium 4, whereas System 2 contains a 1.8 GHz PowerPC processor.
Will these two systems always require the same amount of time to execute a given
program? Justify your answer.
CPU speed is generally measured in gigahertz (GHz), which indicates how many billions
of CPU cycles occur in a second. Since different families of CPUs will different basic
operations using different hardware configurations, some tasks may require more cycles
using one CPU when compared with another. Thus, performance comparisons based on
CPU speed are not always accurate.
14. Consider the following tasks: (1) adding 100 numbers stored in main memory, and (2)
adding a number to itself 100 times. Although both tasks require 100 additions, the
second would be executed much more quickly than the first would. Why?
For the first task, the 100 numbers must each be loaded into registers from main memory
before the additions can take place. Thus, 100 memory loads and 99 additions must take
place. For the second task, only one number must be loaded from memory, before
additions can take place. Thus, 1 memory load and 99 additions must take place.
15. Machine languages are machine-specific, meaning that each type of computer has its own
machine language. Explain why this is the case.
Machine language instructions correspond to the low-level operations that can be
executed by the hardware of the machine. Since different computers have different
CPUS, register configurations, and ALU operations, their machine languages will differ.
16. Within the control unit, what is the role of the program counter (PC)? That is, how is the
PC used in fetching and executing instructions?
The program counter (PC) keeps track of the address of the next program instruction to
be executed. Initially set to the first instruction in the program, it is automatically
incremented as each instruction is loaded, decoded by the control unit, and executed.
17. In a stored-program computer, both instructions and data are stored in main memory.
How does the Control Unit know where the program instructions begin? How does it
know where the instructions end?
In real computers, the starting location for programs is usually maintained by the
operating system, which keeps track of each program in memory and its location. The
14.6
end of a program is usually marked by a special instruction that tells the control unit to
HALT.
18. Describe two advantages of assembly languages over machine languages.
It is much easier for programmers to remember and understand assembly-language
instructions than patterns of 0s and 1s. Furthermore, most assembly languages support the
use of variable names, enabling programmers to specify memory locations by descriptive
names, rather than by numerical addresses.