Sub eax, 0 - is he doing anything?

I just opened the file in IDA Pro, and I found code that looks completely useless. However, I thought it might come in handy. Isn't sub eax,0 just subtracting 0 from eax?

The code:

 hinstDLL= dword ptr 4 fdwReason= dword ptr 8 lpReserved= dword ptr 0Ch mov eax, [esp+fdwReason] sub eax, 0 jz short loc_10001038 
+6
source share
2 answers

The sub command sets the flags ( OF , SF , ZF , AF , PF and CF , according to the documentation ) - the mov instruction is not. jz will only jump if the zero flag ( ZF ) is set, so if you want to switch to a value in eax , this flag must be set accordingly.

+13
source

The sub set the flag to zero if its result is zero. In this case, this means that the zero flag will be set if eax is zero.

Thus, these three commands check if [esp+fdwReason] is equal to zero and in this case go to loc_10001038 .

+6
source

Source: https://habr.com/ru/post/911223/


All Articles