i'm learning to reverse engineer. So i'm coding some programs and try to understand their assembly. I stumbled upon a curious case and i think i can't solve it alone.
Here's the c code:
#include <stdio.h>
int main(){
char *texto = "O numero e %d\n";
int i = 10;
while(i){
printf(texto, i--);
}
return 0;
}
The assembly produced by IDA is the following:
mov eax, [esp+28]
lea edx, [eax-1] ; The part i don't understand
mov [esp+28], edx
mov [esp+4], eax
mov eax, [esp+18h]
mov [esp], eax ; char *
call _printf
What i could understand is that it stores the old value in eax and pushes to stack(I purposedly didn't turn on optimizations) and then it pushes the format.
While that happens in the middle it does the i--
, but i can't understand how it's working. So it get's the address of eax-1
and stores in edx
and then stores it in i
, but eax
doesn't hold an address but a value.
Thanks in advance.
lea edx, [blah-1]
is essentiallymov edx, blah-1
(the latter is obviously not a valid command)