Reputation: 14519
I just opened a file in IDA Pro and I found some code that looks completely useless. However, I thought it might have some use. Doesn't the sub eax,0
just subtract 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
Upvotes: 6
Views: 10685
Reputation: 9867
The sub
instruction will set the zero flag if its result is zero. In this case this means that the zero flag will be set if eax is zero.
So these three instructions check if [esp+fdwReason]
is zero and jump to loc_10001038
in that case.
Upvotes: 6
Reputation: 224964
The sub
instruction sets flags (OF
, SF
, ZF
, AF
, PF
, and CF
, according to the documentation) - the mov
instruction does not. The jz
will jump only if the zero flag (ZF
) is set, so if you want to jump based on the value in eax
that flag has to be set appropriately.
Upvotes: 13