tags:

views:

152

answers:

3

when compiling the instruction

movl 4(%ebp), 8(%ebp)

i got 'too many memory referene', what's wrong with it??

+1  A: 

It is not a legal instruction. For most instructions that reference memory you must move it to/from a register.

GregS
+1  A: 

movl doesn't to memory-memory moves, you have to go by way of a register (thus with two movl instructions).

Alex Martelli
thanks, but why this? is the cpu archtecture that limit this or something else?
freenight
Yes, it's a limitation in the CPU. MOVS is about the only memory-to-memory instruction.
Jerry Coffin
Yeah, memory-to-memory just can't be implemented all that efficiently (non-x86 CPUs tend to have all instructions be just register to register, with load/store as the only register-to-memory ones).
Alex Martelli
+2  A: 

The number before the parenthesis is a byte offset (which causes a memory reference to occur), and you cannot have two of them with movl. You need to move the value temporarily to a register first.

movl 4(%ebp), %ecx
movl %ecx, 8(%ebp)
Marc W