Computer Architecture 1 / Chapter 5: Operations on Memory / Load

Are LOAD And STORE The Same?

In this chapter, we learned about the LOAD and STORE instructions. The two instructions are very similar: both tell the computer to copy values from one memory cell to another. But the two instructions are not the same. To see how they are different, let's compare the two instructions side by side:

NameLOADSTORE
Formatload dst=destination addr=address imm=immediatestore src=source addr=address imm=immediate
Exampleload dst=7 addr=3 imm=1store src=10 addr=4 imm=0

The LOAD instruction allows us to store the source address (cell number) in memory (instead of the instruction). For example, if address is 3, we're not copying the value in cell 3. Instead, the value in cell 3 is the source address.

The STORE instruction allows us to store the destination address in memory. For example, if address is 3, the destination is not cell 3. Instead, the value in cell 3 is the address of the destination.

The ability to store the address in memory is very useful. This allows us to copy values in different places without changing the instruction. For example, consider the following instruction:

load dst=8 addr=2 imm=0

This instruction reads an address in cell #2 and copies the value at the address to cell #8. If cell #2 contains 5, then the source is in cell #5. But if cell #2 contains 15, then the source is in cell #15.

And here is an example of the STORE instruction:

store src=3 addr=5 imm=0

This instruction copies a value stored in cell #3 to an address in cell #5. If cell #5 contains 7, then the value is copied to cell #7. But if cell #5 contains 12, then the value is copied to cell #12.

Notice that in the LOAD instruction, the destination is specified in the instruction. But in the STORE instruction, the source is specified in the instruction. What if we want to store both the source and the destination addresses in memory? Perhaps we can try using both of the LOAD and STORE instructions.

Try writing a program that reads the source address from cell #4, the destination address from cell #5, and copies the value from the source to the destination. Then move to the next lesson to see an example.

Instructions
Memory Cells
Program Counter Time
0 0
LW Computer Simulator
Previous Lesson Next Lesson

Comments

Please log in to add comments