Answer the question
In order to leave comments, you need to log in
How is lea different from mov in this example?
short int A[20];
short int B[20];
...
lea eax, A;
lea ebx, B;
short int *A = new short int[20];
short int *B = new short int[20];
...
mov eax, A;
mov ebx, B;
Answer the question
In order to leave comments, you need to log in
lea inserts data pointer into register, mov copies data
mov eax,1; eax = 1
mov eax,VarName ; will give an error if the size of VarName is greater than eax
. In your example, everything is logical, in 1 case an array is created, through lea the address to the array is put into the register, in the other case we create an array and get its address, and already put it in the register
Let's see what code will be generated in each case:
@_main proc near
push ebp
mov ebp,esp
; short int A[20];
add esp,-40
push ebx
; asm lea eax, A;
lea eax, word ptr [ebp-40]
; return A[0];
movsx eax,word ptr [ebp-40]
@_main proc near
push ebp
mov ebp,esp
; short int *A = new short int[20];
add esp,-4
push ebx
push 40
call @$bnwa$qui
pop ecx
mov dword ptr [ebp-4],eax
; mov eax, A;
mov eax, dword ptr [ebp-4]
; return A[0];
mov eax,dword ptr [ebp-4]
movsx eax,word ptr [eax]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question