LOAD (Direct addressing) and LOADI (Immediate addressing) - what is the difference?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

LOAD (Direct addressing) and LOADI (Immediate addressing) - what is the difference?

User5518
Hi everyone,

currently I'm stuck in chapter 4 on page 60/61:

"LOAD" is explained as followed:

Direct addressing
The most common way to address the memory is to express a specific address or use a symbol that refers to a specific address, as follows:
LOAD R1,67     //  R1<---Memory[67]
// Or, assuming that bar refers to memory address 67:
LOAD R1,bar    //  R1<---Memory[67]

And "LOADI" is explained like this:

Immediate addressing
This form of addressing is used to load constants—namely, load values that appear in the instruction code: Instead of treating the numeric field that appears in the instruction as an address, we simply load the value of the field itself into the register, as follows:
LOADI R1,67    //  R1<---67

If I get it right, it means, that "67" is the address to a - let's say - number in memory. For example wie stored "5" so "101" in this memory at the address "67".

"LOADI" loads the value (so "5" or "101") into the given register (R1) of the CPU. If this is correct, what does "LOAD" do? What does "<---Memory[67]" mean? After reading the description for "LOAD", I thought this command would load the actual value, which is stored at address "67" in the memory into the register "R1". But after reading the description for "Immediate addressing"/"LOADI", I got a bit confused.

Did I get something wrong?

And another point: English isn't my native language (it is german), so I translate every word in the book, which I do not know. "Immediate" was one of them. I looked "Immediate" up and found the translation "direkt", which literally translates to "direct", but "direct addressing" is an own term in this case. So is there another word for "Immediate"? Or this here maybe someone, who can give me a proper translation?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: LOAD (Direct addressing) and LOADI (Immediate addressing) - what is the difference?

WBahn
Administrator
Immediate Addressing:

The instruction contains the actual value that is to be loaded.

Direct Addressing:

The instruction contains the address where the value to be loaded is currently stored.

Indirect Addressing:

The instruction contains the address where the address of the value to be loaded is currently stored.

Reply | Threaded
Open this post in threaded view
|

Re: LOAD (Direct addressing) and LOADI (Immediate addressing) - what is the difference?

User5518
Thanks a lot for these useful explanations!

One more question regarding "Indirect Addressing":

The "Translation of x=foo[j] or x=*(foo+j)" is described as followed:

ADD R,foo,j       // R1<-foo+j
LOAD* R2,R1   // R2<-Memory[R1]
STR R2,x          // x<-R2

The first line is clear to me: The correct address is calculated

Why is in the second line "LOAD*" used and not "LOAD", since the does the same as direct addressing according to the comment?

I assume, that "STR" stores the content of R2 (which is the address to R1, which contains the calculated Address "foo+j"). Or does "STR" stores the actual value of the array at position "foo+j"?

(Or should I open a new thread for this question?)

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: LOAD (Direct addressing) and LOADI (Immediate addressing) - what is the difference?

WBahn
Administrator
You need to really be careful about the subtle distinctions here. It's tricky.

It might be easiest to forget about labels altogether for a moment. In the following I will use constants (since that is all that can be stored in an instruction anyway), so think of 'a' and 'b' as being replaced by hardcoded values.

LOADI a, b //  RAM[a] <- b
LOAD  a, b // RAM[a] <- RAM[b]
LOAD* a, b // RAM[a] <- *RAM[b] or RAM[a] <- RAM[a] <- RAM[RAM[b]]

To make the point more explicit and tied to the book's content, consider:

LOAD R1, bar

The identifier 'bar' is first turned into a constant (67 in the book's example) making this

LOAD R1, 67

Thus

R1 <- Memory[67]

If you were to do

LOAD R1, R2

Then 'R2' is first turned into a constant (most likely 2) making it

LOAD R1, 2

The result will be

R1 <- Memory[2]

By direct analogy,

LOAD R2, R1

would reduce to

LOAD 2, 1

and would result in

Memory[2] <- Memory[1]

This is what we want if R1 holds the actual value that we want stored in R2. But it does not work if R1 contains the address of where the value we want is stored. If that were the case, we need something that does:

Memory[2] <- Memory[Memory[1]]

And THAT is what the LOAD* instruction will do if given

LOAD* 2, 1

which we can make more readable by writing it as

LOAD* R2, R1