【问题标题】:parser: instruction expected on move instruction解析器:移动指令预期的指令
【发布时间】:2014-10-15 13:23:23
【问题描述】:

我正在尝试制作一个简单的汇编程序,即添加两个数字并显示它们,然后减去两个数字并显示它们。但是我遇到了错误:

oppgave3.asm:28: error: parser: instruction expected
oppgave3.asm:29: error: comma, colon, decorator or end of line expected after operand
oppgave3.asm:30: error: symbol `move' redefined
oppgave3.asm:30: error: parser: instruction expected
oppgave3.asm:31: error: comma, colon, decorator or end of line expected after operand
oppgave3.asm:32: error: comma, colon, decorator or end of line expected after operand
oppgave3.asm:33: error: comma, colon, decorator or end of line expected after operand
oppgave3.asm:37: error: symbol `move' redefined
oppgave3.asm:37: error: parser: instruction expected
oppgave3.asm:38: error: comma, colon, decorator or end of line expected after operand
oppgave3.asm:39: error: symbol `move' redefined
oppgave3.asm:39: error: parser: instruction expected
oppgave3.asm:40: error: comma, colon, decorator or end of line expected after operand
oppgave3.asm:41: error: comma, colon, decorator or end of line expected after operand
oppgave3.asm:42: error: comma, colon, decorator or end of line expected after operand

这就是我想要做的:我有两个子例程,一个用于加法,一个用于减法。

section .data
a dw 4
b dw 2


section .bss
c resb 1

section .text
global_start:
_start:

call addition
mov eax,4
mov ebx,1
mov ecx,c
mov edx,1
int 0x80

call subtraction
mov eax,4
mov ebx,1
mov ecx,c
mov edx,1
int 0x80

addition:
move eax,[a]
sub eax '0'
move ebx,[b]
sub ebx '0'
add eax and ebx
add eax '0'
mov [c],eax
ret

subtraction:
move eax,[a]
sub eax '0'
move ebx,[b]
sub ebx '0'
sub eax and ebx
add eax '0'
mov [c],eax
ret

【问题讨论】:

  • 你希望 add eax and ebx 做什么 - 你可能是指 add eax, ebx ?还有许多其他说明也缺少逗号,例如sub eax '0' 应该是 sub eax, '0'。另请注意,错误消息非常有用 - 它们似乎确实告诉您问题所在 - 尝试更仔细地研究它们。
  • sub ebx '0' 应该是sub ebx, '0' 否?

标签: assembly x86 nasm


【解决方案1】:

你写的是“move”而不是“mov”

不被识别为指令助记符的标记被视为标签。像move nop 等价于move: nop。这就是为什么您在以后的某些用途中得到“symbol 'move' redefined”的原因。

还有其他各种语法错误,例如 sub eax and ebx 而不是 sub eax, ebx,以及 sub ebx '0' 中缺少逗号

【讨论】:

  • 天啊!但是我仍然收到错误,它需要在减法和加法操作数之后需要逗号、冒号、装饰符或行尾。
  • 你有sub eax and ebx。不确定你能做到这一点。
【解决方案2】:

我认为你有一个错字。你有一个“移动”指令,而我的猜测是它应该是“mov”,最后没有额外的 e。我不是组装专家,所以我可能在这里错了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-19
    • 2016-09-13
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多