3

I can't figure out why After instruction “LDR R3, R0, 2” is executed, the value stored in R3 is x370C. what does 2 stands for in this instruction? It doesn't look like an immidiate value. I understand that R0 contains x370C at this point. Can someone please help? Many thanks!

.ORIG X3700
 LEA R0, A
 LDI R2, C 
 LDR R3, R0, 2 
 AND R1, R1, #0 
 IN
 ST R0, D 
 JSR  F 
 HALT
 F LD  R1, B
 ADD R1, R1, #1
 BRp F 
 RET

 A .FILL X1234
 B .FILL X370B
 C .FILL X370C
 D .BLKW 2
 E .STRINGZ "ABCD"
 G .FILL X1234
 .END
user4046073
  • 821
  • 4
  • 18
  • 39

1 Answers1

3

The second parameter is the offset of the base address that will be loaded.

I started to take some pictures to post here and make a good explanation but I found an interesting lecture video that will explain much better than words and will save a lot of time.

LC3 Instructions - LD, LDR, LDI, LEA

The video is explaining the differences between the load instructions for the LC3, highlighting the differences between them.

In your example:

You have your data:

A .FILL X1234
B .FILL X370B
C .FILL X370C

Running your code:

LEA R0, A      -- R0 has the address of A
LDI R2, C      -- R2 has value of which address C has
LDR R3, R0, 2  -- R3 has the value of C 
               -- because R0 has the address of A + 2 positions = C
gustavodidomenico
  • 4,640
  • 1
  • 34
  • 50
  • Thanks. It's funny because I actually have watched that video.. I understand that we are supposed to add the 'offset' to R0 and store that address to R3. The problem is that I don't know how to use the '2' in the instruction and add it to the R0. – user4046073 Sep 16 '14 at 12:26
  • Sorry, I really didnt understand, what you mean with `use the 2`? – gustavodidomenico Sep 16 '14 at 12:29
  • I mean the second parameter in "LDR R3, R0, 2" is '2', which is supposed to be the offset, right? but there is no #before it, so it doesn't look like an immediate value. Then how can we add the offset to R0 and how come R3 is x370c? – user4046073 Sep 16 '14 at 12:33
  • Can you take a look at this? http://superuser.com/questions/904324/which-of-the-following-instructions-can-reference-a-memory-location-that-is-100 – committedandroider Apr 21 '15 at 18:46