there.
2 “DLW” in honor of the DLX architecture used by Hennessy and Patterson in their books on computer architecture.
12
Chapter 1
The DLW-1’s Memory Instruction Format
In order to get the processor to move two operands from main memory
into the source registers so they can be added, you need to tell the processor
explicitly that you want to move the data in two specific memory cells to two
specific registers. This “filing” operation is done via a memory-access instruc-
tion called the load.
As its name suggests, the load instruction loads the appropriate data from
main memory into the appropriate registers so that the data will be available
for subsequent arithmetic instructions. The store instruction is the reverse of
the load instruction, and it takes data from a register and stores it in a location in main memory, overwriting whatever was there previously.
All of the memory-access instructions for the DLW-1 have the following
instruction format:
instruction source, destination
For all memory accesses, the instruction field specifies the type of memory
operation to be performed (either a load or a store). In the case of a load, the source field tells the computer which memory address to fetch the data from,
while the destination field specifies which register to put it in. Conversely, in the case of a store, the source field tells the computer which register to take
the data from, and the destination field specifies which memory address to
write the data to.
An Example DLW-1 Program
Now consider Program 1-1, which is a piece of DLW-1 code. Each of the lines
in the program must be executed in sequence to achieve the desired result.
Line
Code
Comments
1
load #12, A
Read the contents of memory cell #12 into register A.
2
load #13, B
Read the contents of memory cell #13 into register B.
3
add A, B, C
Add the numbers in registers A and B and store the result in C.
4
store C, #14
Write the result of the addition from register C into memory cell #14.
Program 1-1: Program to add two numbers from main memory
Suppose the main memory looked like the following before running
Program 1-1:
#11
#12
#13
#14
12
6
2
3
Basic Computing Concepts
13
After doing our addition and storing the results, the memory would be
changed so that the contents of cell #14 would be overwritten by the sum of
cells #12 and #13, as shown here:
#11 #12 #13 #14
12 6 2 8
A Closer Look at Memory Accesses: Register vs. Immediate
The examples so far presume that the programmer knows the exact memory
location of every number that he or she wants to load and store. In other
words, it presumes that in composing each program, the programmer has at
his or her disposal a list of the contents of memory cells #0 through #255.
While such an accurate snapshot of the initial state of main memory may
be feasible for a small example computer with only 256 memory locations,
such snapshots almost never exist in the real world. Real computers have
billions of possible locations in which data can be stored, so programmers
need a more flexible way to access memory, a way that doesn’t require each
memory access to specify numerically an exact memory address.
Modern computers allow the contents of a register to be used as a memory address, a move that provides the programmer with the desired flexibility.
But before discussing the effects of this move in more detail, let’s take one
more look at the basic add instruction.
Immediate Values
All of the arithmetic instructions so far have required two source registers as
input. However, it’s possible to replace one or both of the source registers
with an explicit numerical value, called an immediate value . For instance, to increase whatever number is in register A by 2, we don’t need to load the
value 2 into a second source register, like B, from some cell in main memory
that contains that value. Rather, we can just tell the computer to add 2 to