flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Main > AND vs OR vs TEST

Author
Thread Post new topic Reply to topic
salefrais



Joined: 19 Dec 2006
Posts: 4

AND vs OR vs TEST

Hello! I've seen many uses of "and", "or", and "test" instructions before "JMP" instructions (sorry about that, I knew something seemed wrong here!).
Example:

Code:

invoke MessageBoxHWND_DESKTOPlpSomeTextlpTitleMB_YESNO
and eaxeax ; or eax, eax ; test eax, eax
jnz some_label




Which is better to use? Is there a better instruction?
Thanks in advance.


Last edited by salefrais on 21 Dec 2006, 02:33; edited 2 times in total
Post 19 Dec 2006, 20:11
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7109
Location: Slovakia

we should also take CMP ("proper" way...) into account
Post 19 Dec 2006, 21:03
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15371
Location: 77256 23rd Street

If your goal is optimisation: The most optimal instruction is TEST. This is because there is no write back register resource allocated. With AND and OR each require a register to be written back. CMP requires more bytes to encode and thus pollutes the cache.

If your goal is something else: Use whichever instruction you are most comfortable with.


Last edited by revolution on 19 Dec 2006, 23:09; edited 1 time in total
Post 19 Dec 2006, 23:03
View user's profile Send private message Visit poster's website Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 401
Location: Russian

some values are simplier and better tested with bitwise-operations -> *test* is considered the best way to test on zero val, also if we need to know is there some submask in val we cannot just use cmp. Wast variety of methods there are -> test on (-1= 0F...Fh) =

Code:
inc val
jz @F


etc...

_________________
Any offers?
Post 19 Dec 2006, 23:05
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7109
Location: Slovakia

wait... i missed "before cmp" part. In such case, AFAIK, the instruction does nothing.
Post 19 Dec 2006, 23:14
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
salefrais



Joined: 19 Dec 2006
Posts: 4

I normally use "test" anyway with optimization in mind, so it's good to know that I'm not wrong in doing so. Very Happy Thanks a lot!
Post 20 Dec 2006, 15:28
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2017, Tomasz Grysztar.