flat assembler
Message board for the users of flat assembler.

Index > Main > AND vs OR vs TEST

Author
Thread Post new topic Reply to topic
salefrais



Joined: 19 Dec 2006
Posts: 4
salefrais 19 Dec 2006, 20:11
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 MessageBox, HWND_DESKTOP, lpSomeText, lpTitle, MB_YESNO
and eax, eax ; 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: 7105
Location: Slovakia
vid 19 Dec 2006, 21:03
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: 20451
Location: In your JS exploiting you and your system
revolution 19 Dec 2006, 23:03
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: 392
Location: Russian
asmfan 19 Dec 2006, 23:05
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: 7105
Location: Slovakia
vid 19 Dec 2006, 23:14
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
salefrais 20 Dec 2006, 15:28
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


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.