This is based off this question LEA instruction
这是基于LEA指令的这个问题
Here is the code segment I have a question about
这是我有一个问题的代码段
.ORIG X3700
LEA R0, A
.....
A .FILL X1234
@Paul R, the answer responder, said that "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."
@Paul R,答案响应者,说“代码的来源是x3700,你有12个指令,所以A的地址将是x3700 + x0C = x370C。正如你猜测的那样,LEA R0,A加载地址A进入R0,所以在第一条指令执行完毕后,R0将包含x370C。“
I agree with the first part of what Paul said, his reasoning for why the address of A is x370C. That makes sense.
我同意保罗所说的第一部分,他的理由是为什么A的地址是x370C。那讲得通。
I am confused about the next part, that "LEA R0, A loads the address of A into R0". This is the slide my reference has on the LEA instruction. Lc3 LEA, 5-23
我对下一部分感到困惑,“LEA R0,A将A的地址加载到R0”。这是我参考LEA指令的幻灯片。 Lc3 LEA,5-23
Unlike the ADD and AND instructions, the LEA instruction has only one mode.(reference specifies both modes for ADD and AND.
与ADD和AND指令不同,LEA指令只有一种模式(参考指定ADD和AND的两种模式)。
From this diagram, the second part of LEA, A should be PCoffset 9. However the value of A is 4660(in decimal) from ,A .FILL X1234, which is beyond the PCoffset 9 range, which is -256 to 255).
Can anyone explain what is going on? Am I using the wrong diagram as a reference? Is there another LEA mode?
从该图中,LEA的第二部分,A应该是PCoffset 9.然而,A的值是AFFILL1212的4660(十进制),超出PCoffset 9范围,即-256到255。谁能解释一下发生了什么?我使用错误的图表作为参考吗?还有其他LEA模式吗?
1 个解决方案
#1
Anytime you see a PCoffset as an opcode operand
任何时候您将PCoffset视为操作码操作数
LEA R2, A ; Loads the memory location of A into R2
; LEA, DR, PCoffset9
It's telling you that when your code is assembled it doesn't actually place the label 'A' into your LEA command.
它告诉你,当你的代码被组装时,它实际上并没有将标签“A”放入你的LEA命令中。
Take the following code:
请使用以下代码:
.ORIG X3700 ; Not a code line in the simulator, only used by the assembler
LEA R0, A ; Line 1, starting at x3700
HALT ; Line 2
A .FILL X1234 ; Line 3, located at x3702
.END ; Not a code line in the simulator, only used by the assembler
Now in the simulator the LEA line actually looks like this:
现在在模拟器中,LEA线实际上看起来像这样:
1110 000 000000001 ; Opcode 1110 is LEA
; 000 is our register R0
; 000000001 gives us how many memory locations away A is
And that's what the offset means. It asks the question "How many blocks of memory is A away from me?" and if our variable 'A' is too many blocks away then we will get an error because we cannot represent that value in the offset.
这就是偏移意味着什么。它问了一个问题“有多少块记忆是远离我的?”如果我们的变量“A”距离太多,那么我们将得到一个错误,因为我们无法在偏移量中表示该值。
#1
Anytime you see a PCoffset as an opcode operand
任何时候您将PCoffset视为操作码操作数
LEA R2, A ; Loads the memory location of A into R2
; LEA, DR, PCoffset9
It's telling you that when your code is assembled it doesn't actually place the label 'A' into your LEA command.
它告诉你,当你的代码被组装时,它实际上并没有将标签“A”放入你的LEA命令中。
Take the following code:
请使用以下代码:
.ORIG X3700 ; Not a code line in the simulator, only used by the assembler
LEA R0, A ; Line 1, starting at x3700
HALT ; Line 2
A .FILL X1234 ; Line 3, located at x3702
.END ; Not a code line in the simulator, only used by the assembler
Now in the simulator the LEA line actually looks like this:
现在在模拟器中,LEA线实际上看起来像这样:
1110 000 000000001 ; Opcode 1110 is LEA
; 000 is our register R0
; 000000001 gives us how many memory locations away A is
And that's what the offset means. It asks the question "How many blocks of memory is A away from me?" and if our variable 'A' is too many blocks away then we will get an error because we cannot represent that value in the offset.
这就是偏移意味着什么。它问了一个问题“有多少块记忆是远离我的?”如果我们的变量“A”距离太多,那么我们将得到一个错误,因为我们无法在偏移量中表示该值。