alaphate Posted April 25, 2009 Posted April 25, 2009 Why not mov eax, 0 ?Any advantages using xor eax, eax ?Is it faster?
high6 Posted April 25, 2009 Posted April 25, 2009 (edited) xor eax,eax is 2 bytes, while mov eax,0 is 5.So it is a space thing. Edited April 25, 2009 by high6 1
alaphate Posted April 25, 2009 Author Posted April 25, 2009 Thank you for the answer.xor eax,eax is 2 bytes, while mov eax,0 is 5.So it is a space thing.
KOrUPt Posted April 25, 2009 Posted April 25, 2009 (edited) To slightly clarify. xor r32, r32 Is preferred because it only takes 2 bytes and 1 clock cycle. Whereas: mov r32, imm Takes 5 bytes and 2 clock cycle's + i(1, 2)... Overall it's an optimization thing . KOrUPt. Edited April 25, 2009 by KOrUPt
Nacho_dj Posted April 25, 2009 Posted April 25, 2009 Yea, something similar is the following one. Let's say you want to move 1 to EAX. The immediate instruction is this: B8 01000000 MOV EAX,1 However, many compilers use this instead: 6A 01 PUSH 158 POP EAX As you see clearly, the last one uses only three bytes... just optimizing code. Cheers Nacho_dj
Killboy Posted April 25, 2009 Posted April 25, 2009 isntpush 1pop eaxpretty dumb if you can doxor eax, eaxinc eaxsame bytes, no memory access.ive seen it before too but always wondered what's the point (besides perhaps increasing readability)
quosego Posted April 25, 2009 Posted April 25, 2009 yeah I always use xor eax,eax inc eax..In WL API jumps it leaves rome for a ret 04 or 0c. And you can fit it all into the same space as a jmp xxxxxxxx.
Nacho_dj Posted April 25, 2009 Posted April 25, 2009 (besides perhaps increasing readability) As you surely know, this is not always the reason, since there are times you find a more complicated asm code than the sources themselves... Think that compilation is a mechanical process that sometimes 'mix' instructions loosing the logical order, providing you a strange code... But yes, I agree, yours is still better solution, "imagination is power" Cheers Nacho_dj
Ksbunker Posted June 1, 2009 Posted June 1, 2009 Another trick is to subtract a register from itself therefore always having 0 as the result; just like 'xor eax, eax', it is two bytes;00401000 2BC0 SUB EAX,EAX
Majii Guy Posted June 1, 2009 Posted June 1, 2009 Another trick is to subtract a register from itself therefore always having 0 as the result; just like 'xor eax, eax', it is two bytes;00401000 2BC0 SUB EAX,EAXWhat about if the value stored at EAX is a negative?
Kripton Posted June 2, 2009 Posted June 2, 2009 It doesn't matter because FFFFFFFF - FFFFFFFF will still be 0
SunBeam Posted June 15, 2009 Posted June 15, 2009 Take note of the flags, people. These instructions are used in app code, and if checks are made (not necessarily on EAX) later on, flags are fuxxed (with using XOR for instance) ;-)
Gazooye Posted June 15, 2009 Posted June 15, 2009 xor eax, eaxinc eaxis a bad idea, no memory access but it probably yields an AGI and is thus slower
human Posted June 15, 2009 Posted June 15, 2009 first read intel documentation,since pentium zeroing operation before usage doesnt cause stall. and agi is adress generation not pipeline stall.
Gazooye Posted June 17, 2009 Posted June 17, 2009 first read intel documentation,since pentium zeroing operation before usage doesnt cause stall. and agi is adress generation not pipeline stall.Ye i tend to say agi when i mean stallnevertheless, it's 2 cycles or not?
human Posted June 17, 2009 Posted June 17, 2009 its shouldnt be 2 cycles only 1, but i always use pentium u v pipelines optimizations. still as i can see now with core 2 duo aligment is more important, using mov ax,[] or non pairable movzx eax,[]gives result that movzx is faster due we change aligment of later code.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now