Lc3 LDR and stored value

I can't figure out why After instruction "LDR R3, R0, 2" is executed, the value stored in R3 is x370C.

what does 2 mean in this instruction? It doesn't sound like lasting value. I understand that at this point R0 contains x370C. Can someone 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

      

+3


source to share


1 answer


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

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

LC3 instructions - LD, LDR, LDI, LEA

The video explains the differences between the loading instructions for LC3, highlighting the differences between them.

In your example:



You have data:

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

      

Running the 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

      

+3


source







All Articles