Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So I\'m confused on the LDR opcode thing which is in assembly language. here\'s

ID: 3652946 • Letter: S

Question

So I'm confused on the LDR opcode thing which is in assembly language. here's an example. LDR R4, R2, #-5 I understand the basic idea. For example, for LD R4 #-5, this would mean, take a look at PC and increment it. After doing so, subtract 5 from it. then go that whatever THAT memory is. And put it into R4, which is the destination register. I understand that where the Base is PC+1 and the offset is whatever you put in it. I mean, I know what PC is. I can just take a look at it wherever the last memory location instruction was executed for example. But I don't understand for LDR. I know what it's saying. It wants me to do R2 (which is base) subtract that by 5. But I mean, WHAT'S R2? Is it 2? What's the value assigned to it? I hope you understand my question. Basically I'm confused on what R2 stands form. I know the idea where you gotta subtract 5 from R2. Then go to that memory location and store it in destination R4. But basically, WHAT IS R2 and it's corresponding value? Thanks and I will give a lifesaver to whoever answers it to the point where I understand what they mean. Muchas gracias! If you know, ANSWER FAST! I need this so I can finish my program. Thanks!

Explanation / Answer

LDR syntax is like this:

LDR DestinationResister, BaseResister,Offset

But the syntax of LD is like this:

LD DestinationResister,Offset

In LD the base resister is always PC. But in LDR you can choose any resister as base resister.

In your example

LDR R4, R2, #-5 ----> you have taken R2 as base register, suposse you have stored 1000H in R2.

So by executing the above instruction the value at memory 1000-5=(0FFB)H , will be loaded into R4.

Here H represents the Hexadecimal number.

Similarly you can take any resister as you wish.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote