In the following assembly code I am trying to implement a multiplication method using bitwise shifts etc but I am getting two errors over and over, "too many memory references for 'mov'" as well as "ambiguous operand size for 'cmp/and/mov/shl/shr'". Any ideas?
Thanks guys. The associated errors are below, as requested.
.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 e开发者_如何学Ccx,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
Error messages:
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'
You are missing %
in front of all your register names:
So it should be:
mov %eax,0
mov %ebx,x
mov %edx,y
As it is, it is parsing them as variables to memory locations. (without the %
, they'd be the same as x
and y
which are memory references.)
EDIT:
Ah... Looks like ughoavgfhw already pointed this out in the comments.
精彩评论