tags:

views:

224

answers:

2

I'm trying to learn assermbly (so bear with me) and I'm getting a compile error on this line:

mov byte [t_last], [t_cur]

The error is

error: invalid combination of opcode and operands

I suspect that the cause of this error is simply that its not possible for a mov instruction to move between two memory addresses, but half an hour of googling and I haven't been able to confirm this - is this the case?

Also, assuming I'm right that means I need to use a register as an intermediate point for copying memory:

mov cl, [t_cur]
mov [t_last], cl

Whats the recommended register to use (or should I use the stack instead)?

+3  A: 

Your suspect is correct, you can't move from memory to memory.

Any general-purpose register will do. Remember to PUSH the register if you are not sure what's inside it and to restore it back once done.

klez
Is there any advantage to using a register over pushing the data itself onto the stack?
Kragen
Pushing on and later popping from the stack adds two additional memory accesses.
drhirsch
A: 

There's also a MOVS command from moving data from memory to memory:

MOV SI, OFFSET variable1
MOV DI, OFFSET variable2
MOVS
ymv
Will work, but it requires extra care: you need to save si and di registers. I guess it's not worth it for copying one byte.
sharptooth
The string commands on x86 can be considered obsolete. Never use them. They are never faster than copying "by hand", but in most cases much slower.
drhirsch