Reputation: 3
I found this asm instructions who push a parameter into the stack before a call, but i think there is some useless instructions.
mov eax,esi
neg eax
sbb eax,eax
lea ecx,[esp+10h]
and eax,ecx
push eax
Can i just replace theses instructions with the following:
lea ecx,[esp+10h]
push ecx
Upvotes: 0
Views: 660
Reputation: 20057
You can replace those instruction with
lea eax, [esp+10]
test esi, esi
cmovz eax, esi ;; push zero (i.e. esi) iff esi==0
push eax
or
test esi, esi
jz skip
lea esi, [esp+10]
skip: push esi
Neg will subtract eax from 0 and that produces carry flag unless eax==0; When carry flag is set, sbb a,a produces -1 (otherwise 0), that is used as a selection mask. It's not completely clear that cmov instruction will be faster than the branch.
Upvotes: 0
Reputation: 882586
No, I don't believe what you have is equivalent. The sbb
instruction may leave eax
as zero (all 0 bits) or negative one (all 1 bits), which will definitely affect what happens to the value pulled from ecx
in the and
instruction.
It looks like the original code will push either esp+10h
or 0
, depending on what was in esi
to start with.
Upvotes: 1