Why use or al, al instead of cmp al, 0?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

Why use or al, al instead of cmp al, 0?

Post by matias_beretta »

I noticed that people use: or al, al instead of cmp al, 0.

Is it the same?
Matías Beretta
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post by earlz »

you will get more replies if you name your topic more appropriately...
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

thanks

Post by matias_beretta »

thanks, this answer helped me a lot!
Matías Beretta
OrOS
Member
Member
Posts: 143
Joined: Sat Sep 08, 2007 11:26 pm
Location: Canada

Post by OrOS »

I assume that was sarcasm....
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Re: Question

Post by frank »

matias_beretta wrote:I noticed that people use: or al, al instead of cmp al, 0.

Is it the same?
It achieves the same result, but maybe or al, al is faster or takes up less space in the binary.

EDIT: Well actually they are the same size. So that rules that out. However or eax, eax is 1 byte shorter than cmp eax, 0.
Last edited by frank on Sun Sep 23, 2007 3:50 pm, edited 1 time in total.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post by earlz »

well, isn't 'cmp al,al' just 'and al,al' without changing the destination?

so, or al,al would not be faster.... I've also never seen this though(I don't look at much asm source though..)

...sorry for useless response...I should've put what I put here, but anyway...
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Re: Question

Post by Craze Frog »

matias_beretta wrote:I noticed that people use: or al, al instead of cmp al, 0.

Is it the same?
cmp performs a subtraction and or only a bitwise boolean operation, so it is theorethically slightly faster. But or destroys the value of al.
User avatar
kataklinger
Member
Member
Posts: 381
Joined: Fri Nov 04, 2005 12:00 am
Location: Serbia

Re: Question

Post by kataklinger »

Craze Frog wrote:But or destroys the value of al.
or al,al doesn't change value of al!
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Re: Question

Post by Craze Frog »

kataklinger wrote:
Craze Frog wrote:But or destroys the value of al.
or al,al doesn't change value of al!
You're right. I forgot the source and destination had the same value...
Post Reply