2018년 12월 26일 수요일

[Assembly code] Difference between mov and lea

A. _AddressOfReturnAddress ()
lea eax [ebx+4]
 mov ret, eax 
B. _ReturnAddress () 
mov eax [ebx+4] 
mov ret, eax

Both of above return eax samely but the contents are different. A method's return value is the pointer that contains address of return address. "lea eax [ebx+4]" means set the result of the calculate, ebx+4, to eax. At the next line, the value of eax is delivered to ret. It is the result of assembly code "mov". If you want to access the return address, it is possible (via the * operator) through the address pointed to by the pointer returned by method.
The other wise, B method retuns the return address itself. So, you don't need to do additional thing like using * operand.
To sum up, the difference between "mov a b" and, "lea a b" is below.
 - mov just set b to a
 - lea set a the value to which the address b is pointing.

댓글 없음:

댓글 쓰기