我不断收到并解决我的汇编语言的错误
因此,我正在为以下内容创建一种汇编语言:
X = 5
Y = 7
FOR I = 1 TO 9
Y = Y + I
IF T(I) = J(I) + X THEN J(I) = T(I) * 4 - Y
ELSE J(I) = J(I) - T(I)
END_FOR
并不断收到
"Address Error: Instruction at 418 accessing address 44f
Execution halted"
到目前为止我所拥有的代码是:
ORG $400
MOVEA #T,A0
MOVEA #J,A1
MOVE.B #1,D0 //D0 is a counter to hold I
MOVE #5,D1 //X = 5
MOVE #7,D2 //Y = 7
NEXT
ADD D0,D2 //Y = Y + I
MOVE (A0),D3
MOVE (A1),D4
MOVE D4,D5 //D5 is a temp copy of J(I)
MOVE D5,D1
CMP D5,D3 //IF T(I) = J(I) + X
BNE ELSE
SUB D2,D3
MULU #4,D3
MOVE D3,(A1)
BRA END_LOOP
ELSE
SUB D3,D4 //J(I) = J(I) - T(i)
MOVE D4,(A1)
END_LOOP
ADDA #2,A0 //POINT TO NEXT ELEMENT IN T
ADDA #2,A1 //POINT TO NEXT ELEMENT IN J
ADD #1,D0
CMP #9,D0
BNE NEXT
MOVE.B #4,D0
TRAP #15 //; halt simulator
* Variables and Strings
T DC.B 6,2,5,4,9,7,3,1,0
J DC.B 5,7,1,9,2,5,6,6,1
END $400 //; last line of source
我忽略了什么?
So I am creating an assembly language for the following:
X = 5
Y = 7
FOR I = 1 TO 9
Y = Y + I
IF T(I) = J(I) + X THEN J(I) = T(I) * 4 - Y
ELSE J(I) = J(I) - T(I)
END_FOR
and keep recieving a
"Address Error: Instruction at 418 accessing address 44f
Execution halted"
The code I have so far is:
ORG $400
MOVEA #T,A0
MOVEA #J,A1
MOVE.B #1,D0 //D0 is a counter to hold I
MOVE #5,D1 //X = 5
MOVE #7,D2 //Y = 7
NEXT
ADD D0,D2 //Y = Y + I
MOVE (A0),D3
MOVE (A1),D4
MOVE D4,D5 //D5 is a temp copy of J(I)
MOVE D5,D1
CMP D5,D3 //IF T(I) = J(I) + X
BNE ELSE
SUB D2,D3
MULU #4,D3
MOVE D3,(A1)
BRA END_LOOP
ELSE
SUB D3,D4 //J(I) = J(I) - T(i)
MOVE D4,(A1)
END_LOOP
ADDA #2,A0 //POINT TO NEXT ELEMENT IN T
ADDA #2,A1 //POINT TO NEXT ELEMENT IN J
ADD #1,D0
CMP #9,D0
BNE NEXT
MOVE.B #4,D0
TRAP #15 //; halt simulator
* Variables and Strings
T DC.B 6,2,5,4,9,7,3,1,0
J DC.B 5,7,1,9,2,5,6,6,1
END $400 //; last line of source
What am I overlooking?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您更改所有
MOVE
、ADD
、SUB、
CMP
至MOVE.B
、ADD.B
、SUB.B
、<代码>CMP.B。我假设为.B
,因为您的变量已声明为DC.B
。即使您没有收到错误,您也应该指定大小。 注意需要更改的主要是访问内存的MOVE
,原因如下,但它们都应该被指定。无论如何,错误发生在:
MOVE (A1),D4
。如果您跟踪并查看寄存器,您将看到之前的类似指令 (MOVE (A0),D3
) 将一个字而不是一个字节读入D3
:D3=00000602
。它将T
中的前两个字节读取到D3
中。MOVE (A1),D4
也想读取一个 WORD,这次是从J
读取。但是,由于您告诉汇编器
DC.B
,它会对齐内存,以便您可以以字节(而不是字)的形式访问数组。由于您的MOVE
指令等默认为MOVE.W
,您还可以将DC.B
更改为DC.W
code>,错误就会消失。但不要这样做,只是向您展示错误发生的方式和原因,您应该按照我上面提到的方式指定大小。另请注意,使用诸如 MULU 之类的指令,如果您只想将单个字节相乘,则应确保寄存器的较高字节被清零,因为它至少相乘每个操作数的 WORD。由于您没有将超过一个字节的任何内容移动到
D3
中,因此较高的字节无论如何都是 0。另一件事,
END $400
通常应该类似于END START
,即:编辑:只是想我会指出(如果不是的话)已经很明显了)您应该修复
A0
和A1
的增量,即。阅读 JustinP 的回答。It'll execute without any errors (not sure if it does the right calculations but that's up to you since it's homework) if you change all your
MOVE
,ADD
,SUB
,CMP
toMOVE.B
,ADD.B
,SUB.B
,CMP.B
. I'm assuming.B
since your variables are declaredDC.B
. Even if you're not getting errors you should specify the size. Note the main ones that need changing are theMOVE
s that access memory, for the reasons below, but they should all really be specified.Anyway the error occurred at:
MOVE (A1),D4
. If you trace through and look at the registers you'll see the similar instruction before that (MOVE (A0),D3
) was reading a WORD rather than a BYTE intoD3
:D3=00000602
. It read the first two bytes fromT
intoD3
.MOVE (A1),D4
also wants to read a WORD, this time fromJ
.However, since you told the assembler to
DC.B
, it aligned the memory so that you can access your arrays as BYTEs as opposed to WORDs. Since yourMOVE
instructions and such were defaulting toMOVE.W
, you could also changeDC.B
toDC.W
, and the error would go away. Don't do that though, just showing you how and why the error occurs, you should specify the sizes as I mentioned above.Also take note that with instructions like
MULU
, if you only want to multiply single BYTEs together you should make sure that the higher BYTEs of your register(s) are zeroed out, since it multiplies together at least a WORD from each operand. Since you haven't moved anything more than a BYTE intoD3
the higher BYTEs are all 0 anyway.Another thing,
END $400
should usually be something likeEND START
, ie:EDIT: Just thought I'd point out (if it wasn't already obvious) that you should fix your increment of
A0
andA1
, ie. read JustinP's answer.不知道 Easy68K,但在我知道的其他汇编器中,名为 DC.B 的指令不会分配字节吗?在这种情况下,您需要 adda #1,a0 来迭代这些?
Don't know about Easy68K, but in other assemblers that I have known wouldn't an instruction called DC.B allocate bytes? In which case you'd need adda #1,a0 to iterate through these?