Question

I saw assembly code like,

MOV [EAX], EBX

the above line, They are mentioned [EAX] is memory and EBX is Register. So, here what is the difference between [EAX] and EBX. What will happen in above instruction.

Was it helpful?

Solution

In this syntax, brackets around a register means a memory location is used (as source or destination, according to the instruction) with starting address specified at the register (EAX in your case). For example, if EAX contained 1344 before the instruction, value from EBX is copied to logical memory addresses 1344-1347 (because this is 4 byte copying).

I hope this is enough to untangle them in your mind:) and please notice more complex cases are possible (e.g. MOV [EAX+ECX],EBX forms destination address as sum of two register values).

OTHER TIPS

Let's say that the first 16 bytes in memory starting at address 0x1000 contains the following:

0x1000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

Now let's say that EAX contains 0x1002 (just an example; don't try to write to arbitrary addresses in real code) and EBX contains 0x12345678.

MOV [EAX],EBX would write the value of EBX (which is 32 bits == 4 bytes) to memory starting at the address contained in EAX, so afterwards the memory would look like:

0x1000: 00 01 78 56 34 12 06 07 08 09 0A 0B 0C 0D 0E 0F

Note the order in which the bytes were written. This is because x86 processors are little-endian.

If you had done MOV EAX,EBX you would have copied the value 0x12345678 to the register EAX and left the memory at 0x1002 unchanged.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top