【问题标题】:First assembly program error "too many references for mov"第一个汇编程序错误“mov 的引用过多”
【发布时间】:2011-12-05 17:37:56
【问题描述】:

在以下汇编代码中,我尝试使用按位移位等实现乘法方法,但我一遍又一遍地遇到两个错误,“'mov' 的内存引用过多”以及“'cmp' 的操作数大小不明确/和/mov/shl/shr'”。有什么想法吗?

谢谢各位。根据要求,相关错误如下所示。

    .intel_syntax
    .data

    .globl x
x:  .long 0

    .globl y
y:  .long 0
    .text

    .globl multiply
multiply:
    push    ebp #These two statements are necessary
    mov ebp,esp

    mov eax,0
    mov ebx,x
    mov edx,y

LOOP:
    cmp ebx,0
    je  DONE

    mov ecx,ebx
    and ecx,1
    cmp ecx,1
    jne LOOPC   #jump to continued loop if low_bit(x) not 1

    add eax,edx

LOOPC:
    shr ebx,1
    shl edx,1
    jmp LOOP

DONE:
    pop ebp #Necessary statement
    ret     #return

错误信息:

multiply.s: Assembler messages:
multiply.s:0: Warning: end of file in comment; newline inserted
multiply.s:15: Error: too many memory references for `mov'
multiply.s:17: Error: ambiguous operand size for `mov'
multiply.s:18: Error: too many memory references for `mov'
multiply.s:19: Error: too many memory references for `mov'
multiply.s:22: Error: ambiguous operand size for `cmp'
multiply.s:25: Error: too many memory references for `mov'
multiply.s:26: Error: ambiguous operand size for `and'
multiply.s:27: Error: ambiguous operand size for `cmp'
multiply.s:30: Error: too many memory references for `add'
multiply.s:33: Error: ambiguous operand size for `shr'
multiply.s:34: Error: ambiguous operand size for `shl'

【问题讨论】:

  • 如果您指出出现这些错误的行会很有帮助。
  • 尝试.intel_syntax noprefix 而不是只使用.intel_syntax(或将% 添加到所有寄存器中)
  • 按要求添加错误。
  • @flapjackery:那么,你说的代码在哪里?

标签: assembly bit-manipulation


【解决方案1】:

您在所有注册名称前都缺少%

应该是这样的:

mov %eax,0
mov %ebx,x
mov %edx,y

事实上,它将它们作为变量解析到内存位置。 (没有%,它们将与xy 相同,它们内存引用。)

编辑:

啊...看起来 ughoavgfhw 已经在 cmets 中指出了这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-08
    • 2022-12-12
    • 1970-01-01
    • 2016-09-06
    • 2013-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多