Build: difference between add command and operator addition

Is there a difference between the following two:

mov     eax, [eax+4]

and

add     eax, 4
mov     eax, [eax]

If not, does the assembler choose which one to choose for any optimization?

+4
source share
2 answers

There are several differences between the two parts of the code. Firstly, the encoding and size of the commands. The first is encoded as follows:

8b 40 04                mov    eax, [eax+4]

... for the amount of 3 bytes.

For the second ...

83 c0 04                add    eax, 4
8b 00                   mov    eax, [eax]

... total 5 bytes.

In addition, the add command sets OF(overflow), SF(sign), ZF(zero), AF(setting / auxiliary), CF(carry) and PF(parity) according to the result. The instruction movdoes not set or cross any of these flags.

, ... . , . . , 3- , .

!

+4

, . , . add , [eax+4] - . , . .

, , , , .

+2

All Articles