This code is from Introduction To Assembler (the chm file from the MASM32 distribution),
from the "Addressing and Pointers" chapter.
mov eax, lpvar ; copy address into eax
mov eax, [eax] ; dereference it
mov nuvar, eax ; copy eax into new variable
Why don't we do directly this?
mov nuvar, [lpvar]
Direct memory to memory moves work only with three opcodes: push, pop and movs. However, you can use the
m2m macro:
include \masm32\include\masm32rt.inc
.data
MySrcVar dd 123
MyDestVar dd 0
.code
start: m2m MyDestVar, MySrcVar
MsgBox 0, str$(MyDestVar), "Masm mem to mem:", MB_OK
exit
end start
Quote; memory to memory assignment
; ----------------------------
m2m MACRO M1, M2
push M2
pop M1
ENDM
it is a little bit involved, but you can use VirtualProtect to allow modification of immediate values in the code segment
usually called self-modifying code
mov SomeLabel,0FFFFFFFFh
ImmedLabel LABEL DWORD
.
.
.
mov ImmedLabel-4,eax
Sergiu,
There is no opcode built into the hardware to perfom direct memory to memory copy, the opcodes that JJ listed for you do a similar thing but almost all opcodes that involve data movement require a register on one side, its built into the hardware that way.