I'm currently looking into assembly and disassembled some code(x86) and there I tried to recreate the C-Code from it. I know at least the basics of the registers and programming in general. But I can't make sense of the usage of ESI in the case of:
mov esi, [esp+10h]
lea esi, [esi+0]
I don't know for sure what esp+10h
is in this case, but I don't think it matters, since it should just be some random 32-bit-value, right?
From what I know is that mov esi, [esp+10h]
will copy the data(the actual value) from the adress esp+10h
and store it in ESI. So esi
should be some kind of data right now. But then afterwards lea esi, [esi+0]
comes and interprets esi+0
, which is data, as an adress and writes this in esi
.
In another thread on stackoverflow I read, that lea esi, [esi+0]
is actually is a nop
(What is the meaning of lea 0x0(%esi),%esi). That makes sense since it shouldn't modify the address. But that's confusing when esi
is data on usage. So my C-code for it looks something like this:
int esi = *(esp + 0x10); //move data from esp+10h to esi
int* esi = &esi; //write the address of esi+0 to esi which is
//actually an int and not int*
So my question is if there is any distinction between data and adress on an register-level or if it's just interpreted as it is since it looks the same(32-bit register). My other question is what this code now actually does and what ESI is at the end? Does mov
always copy data? Does lea
always copy an address of doesn't it matter anyways?
As you might have guessed by now, I'm pretty confused and maybe I'm just thinking too far. Please have mercy with me :D