freenight
freenight

Reputation: 163

gas: too many memory reference

When compiling the following instruction:

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

I got: too many memory reference.

What's wrong with it?

Upvotes: 7

Views: 11098

Answers (3)

Marc W
Marc W

Reputation: 19241

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)

Upvotes: 9

Alex Martelli
Alex Martelli

Reputation: 881873

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

Upvotes: 2

President James K. Polk
President James K. Polk

Reputation: 41995

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

Upvotes: 2

Related Questions