Alright so I have this line in my assembly
MOV EAX, DWORD PTR DS:[ESI]
where ESI is 00402050 (ascii, “123456789012”)
After this instruction: EAX = 34333231
What really happened here? How is this value calculated, and why?
Where could I get some good reference on this kind of thing?
Registers in square brackets such as
[ESI]are dereferenced pointers. The instruction you quote moves theDWORD(a 32-bit/4-byte value) in memory location specified byESIinto registerEAX. In your case, memory location00402050, read as aDWORD, contains34333231.Written in pseudo-C:
In your case, it is not true that
0x00402050“equals” the string"1234567890"— rather it points to the memory which contains that string.The value which you obtain,
0x34333231is comprised from the ASCII values for the digits"1234", which are the first four bytes (i.e., the firstDWORD) of the string. They appear in reversed order because the Intel architecture is “little endian” in the byte representation of aDWORDin memory.In your example at this time, the
movinstruction is loading ASCII characters as if they were the four bytes of anunsigned longvalue, when they are actually a string of single-byte characters.