问题
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
回答1:
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
来源:https://stackoverflow.com/questions/25868391/lc3-ldr-instruction-and-the-value-stored