LC3 LEA instruction and the value stored

user3735871 picture user3735871 · Sep 16, 2014 · Viewed 14.3k times · Source

I am confused by this question: What is the value stored in register 0 after instruction “LEA R0,A" is executed? How come the answer is x370C ? I reckon it is supposed to load the address of A into R0? If so how do we know the address? 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

Answer

Paul R picture Paul R · Sep 16, 2014

The origin of the code is x3700, and you have 12 instructions, so the address of A will be x3700 + x0C = x370C. As you guessed, LEA R0,A loads the address of A into R0, so R0 will contain x370C after that first instruction has been executed.

        .ORIG X3700
3700     LEA R0, A
3701     LDI R2, C
3702     LDR R3, R0, 2 
         ...
370b     RET

370c     A .FILL X1234
         ...