This question is really troubling me for some time now,as always i tried to search and read about it. But the info i got was really vague and didnt provided with the clear idea.So can someone plz explain:
Whats the difference between "lea" and "mov".
and between "mov" and "movzx".
Their usages,where and why in comparision to each other.
Hi again.
'lea' means LOAD EFFECTIVE ADDRESS
lea ebx,string1 will load the address of the string (the location of the first byte of the char array)
the MOV instruction moving a variable (register,or memory's) exact value in the destination operand.
mov ebx,OFFSET string1 will load the effective address of "string1" as well
....
mov ebx,string1 will cause an error 'invalid instruction operands' because string1 is a BYTE array, not a DWORD value like the address of string1.
I suggest you to learn some more about arrays and pointers,it's good for you!
mov op1, op2 puts the value of op2 into op1
lea op1, op2 puts the address of op2 into op1
Use of mov: copying data between registers and memory.
Use of lea: performing complex calculations with one instruction and getting the address of a stack variable
e.g. multiply eax by 3: lea eax,[eax*2+eax]
get the addess of local variable number 3: lea esi,[ebp-8]
mov requires that both operands be the same size:
mov al,ecx is not allowed.
movzx allows you to copy a smaller operand to a bigger one, zeroing out the unused bits.
movzx eax,cl is functionally equivalent to
xor eax,eax then mov al,cl
Thanx AeroASM
The info helped a lot.just one more question[a stupid one].
Quote from: AeroASM on December 08, 2005, 06:19:09 PMmovzx allows you to copy a smaller operand to a bigger one, zeroing out the unused bits.
Does that mean (movzx eax,ebx) is equals to (mov eax,ebx)?
shaka_zulu
Ya, i too think so.I will,am a bit lazy u c :bg
Yes, movzx eax,ebx is functionally equivalent than mov eax,ebx, but it may be slower.
AeroASM,
Quote
Yes, movzx eax,ebx is functionally equivalent than mov eax,ebx, but it may be slower.
It is not functionally equivalent, but it sure is a lot slower. That is because one has to
correct the invalid instruction and code it the correct way. Ratch
movzx eax,ebx
TEST.ASM(25) : error A2070: invalid instruction operands
For reference only: MOVZX and MOVSX with both 16-bit operands is encodable: (MASM doesn't allow it though)
660FB7C3 MOVZX AX,BX
660FBFC3 MOVSX AX,BX
Both work the same way like MOV AX,BX :P
MazeGen,
It's a great way to use a 4 byte instruction when a three byte instruction does the same thing. Probably slower too. Ratch
Quote
0000000A 66 0F B7 C3 BYTE 066H,0FH,0B7H,0C3H
0000000E 66 0F BF C3 BYTE 066H,0FH,0BFH,0C3H
00000012 66| 8B C3 MOV AX,BX