I understand that dword ptr is a size directive that indicates the size of what is being moved where and I know that mov eax, eax is a form of nop code but what does this do?
I think it swaps the address of eax with the hex value inside but I am not too sure or even know why this would happen.
mov eax, ebx – 2 operands, source and destination. mov eax, 5 – one operand is a literal. mov y, eax – memory to register movement. add eax, 5 – 2 operands for add. mul value – 1 operand for mul, other operand is eax.
"eax" is the destination of the move, also known as the "destination operand". It's a register, register number 0, and it happens to be 32 bits wide, so this is a 32-bit move. 5 is the source of the moved data, also known as the "source operand".
Basically, it means "the size of the target operand is 32 bits", so this will bitwise-AND the 32-bit value at the address computed by taking the contents of the ebp register and subtracting four with 0.
The size directives BYTE PTR, WORD PTR, and DWORD PTR serve this purpose, indicating sizes of 1, 2, and 4 bytes respectively.
It loads EAX with the DWORD value that EAX was originally pointing to.
In C terms its dereferencing the value that was originally held in EAX as follows: "eax = *eax"
The instruction mov eax, eax
may be a no-operation code but that is not what you have here. You're loading from memory, as indicated by the []
"contents-of" characters.
It loads eax
with the contents of memory (a 32-bit dword
in this case) that is currently pointed to by eax
.
Perhaps a graphical picture would help:
Before:
eax: 0x12345678
memory @ 0x12345678: 0xffffffff
After:
eax: 0xffffffff
memory @ 0x12345678: 0xffffffff
As to possible uses, there are no doubt many. One that pops into mind immediately is a linked list structure where you have something like this for a single element in the list (pseudo-assembly):
next: word ? ; one word.
payload: byte ?(32) ; 32 bytes.
If eax
is used as a pointer to one of those elements, getting the next element would be done with the instruction you see:
mov eax, dword ptr [eax]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With