2011-10-11 89 views
1

在下面的彙編代碼中,我試圖實現一個使用按位移等乘法的方法,但我一遍又一遍地得到兩個錯誤,「對於'mov' 「以及」cmp/and/mov/shl/shr'「的模糊操作數大小。」有任何想法嗎?第一個彙編程序錯誤「mov的引用太多」

謝謝你們。根據要求,相關的錯誤在下面。

.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' 
+1

如果您指出了發生這些錯誤的行,這將會很有幫助。 –

+5

嘗試'.intel_syntax noprefix'而不是'.intel_syntax'(或將'%'添加到您的所有寄存器中) – ughoavgfhw

+0

按請求添加錯誤。 – mathjacks

回答

6

你缺少%在你所有的寄存器名字前面:

所以它應該是:

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

由於它是,它將它們作爲變量解析到內存位置。 (不%,他們會是一樣的xy內存引用。)

編輯:

啊......貌似ughoavgfhw已經指出了這一點的意見。