如何使用LC3汇编中的LEA指令修复“偏移超出范围”错误

时间:2019-01-15 21:48:33

标签: assembly lc3

我刚刚开始为我的机器组织课程学习LC3汇编。我需要在LC3汇编中编写一个小程序来计算以零结尾的正数列表的总和。我的程序需要从x3000位置开始,而我的数据(数字列表)应该从x4000开始。我是这样写的:

.ORIG x3000
AND R1,R1,x0      ;clear R1 to be used for the sum
LEA R2,x4000      ;load the starting address of the data
LDR R3,R2,x0      ;load the next number to be added
LOOP ADD R1,R1,R3 ;add the next number to the sum
ADD R2,R2,x1      ;increment the pointer
LDR R3,R2,x0      ;load next number to be added
BRp LOOP          ;loop if next number is positive
HALT
.END

但是我得到这个错误:

at line 3: while parsing the offset for a LEA: offset 16384 is out of range; 
it must fit into 9 bits, so it should be between -256 and 255, inclusive

我很难确切地知道我应该如何使用LEA指令来使其执行我想要的操作。我该如何更改?

编辑3:

.ORIG x3000
AND R1,R1,x0      ;clear R1 to be used for the sum
LD R2,NUMBERS     ;load the starting address of the data
LDR R3,R2,x0      ;load the next number to be added
LOOP ADD R1,R1,R3 ;add the next number to the sum
ADD R2,R2,x1      ;increment the pointer
LDR R3,R2,x0      ;load next number to be added
BRp LOOP          ;loop if next number is positive
HALT
NUMBERS .FILL x4000
.END

0 个答案:

没有答案