The LOAD Instruction
The load (LOAD) instruction copies a value from one memory cell to another.
The LOAD instruction format is:
load dst=destination addr=address imm=immediate
The value at memory cell #source is copied to destination, where source is the value in memory cell #address + immediate.
Here is an example:
| Memory Cells |
|---|
| Program Counter | Time |
|---|---|
| 0 | 0 |
Instruction #0 is a LOAD instruction. dst is 5, so the destination is cell #5. addr is 1, but this does NOT mean that the source is cell #1. Rather, the source is the value of cell #1, which is 3, plus the immediate. But imm is 0, so the source is cell #3. Thus, the computer copies the value of cell #3, which is 7, to cell #5.
More generally, if the following are true:
- the PC at time t = i
- instruction #i is
load dst=dst addr=addr imm=imm
Then we can conclude the following:
- value of cell dst at time (t + 1) = value of cell ((value of cell addr at time t) + imm) at time t
- the PC at time (t + 1) = x + 1
As we can see, the PC increases by 1. Also, memory cells other than the destination are not affected by this instruction.
For example, if the following are true:
- the PC at time 0 = 0
- instruction #0 is
load dst=5 addr=1 imm=0 - value of cell 1 at time 0 = 3
- value of cell 3 at time 0 = 7
Then we can conclude the following:
- value of cell 5 at time (0 + 1) = value of cell ((value of cell 1 at time 0) + 0) at time 0
- the PC at time (0 + 1) = 0 + 1
Value of cell #1 is 3, so the first conclusion reduces to:
value of cell 5 at time (0 + 1) = value of cell (3 + 0) at time 0
This simplifies to:
value of cell 5 at time 1 = value of cell 3 at time 0
Since the value of cell 3 is 7, we conclude that:
value of cell 5 at time 1 = 7
We can also simplify the second conclusion to:
the PC at time 1 = 1
Comments
Please log in to add comments