Question

Can I use mov with an indirect operand as both the source and destination?

E.g.

mov eax, OFFSET foo
mov esi, OFFSET bar
mov [eax],[esi + LENGTHOF bar]

From what I've tried I'm guessing you can't due to an invalid instruction operand error. But I haven't read anywhere that explicitly states you can't so I want to make sure it's not due to some other error.

Was it helpful?

Solution

The x86 mov instruction does not support memory-to-memory moves.

Have a look at Volume 2: Instruction Set Reference, namely the MOV instruction. There are reg <- reg, mem <- reg, and reg <- mem forms, but no mem <- mem.

To move data from memory to memory, one must either use an intermediate register, or the movs instruction, which moves a value from address DS:ESI to ES:EDI. This is the reason those registers are named as such (source index, and destination index).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top