NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: ThatGuy22 on December 15, 2010, 02:50:34 PM

Title: How does the test instruction work?
Post by: ThatGuy22 on December 15, 2010, 02:50:34 PM
I was wondering how the test instruction works, I know it does almost the same thing as and. Does the test instruction take a value you give it and tell you if that bit is set like:
test ax, 2 - would this test ax to see if the second byte is set like 00000010 since, 00000010 in binary is equivalent to 2?
like wise would this test for 3:
test ax, 3 - testing to see if 00000011 is set?

-In short does the test instruction see if the binary value that makes up the number you give it is set within the first operand?
-If I am incorrect can someone explain it to me please.
Title: Re: How does the test instruction work?
Post by: cm on December 15, 2010, 06:03:13 PM
I was wondering how the test instruction works, I know it does almost the same thing as and.

The only difference is that "test" only sets the flags (you're primarily interested in the Zero Flag (ZF) here) while "and" sets the flags (ZF) as well as the destination operand.

Quote
test ax, 2 - would this test ax to see if the second byte is set like 00000010 since, 00000010 in binary is equivalent to 2?

Second bit; besides that, yes, this instruction would test whether the second bit is set. You can then use a "jz" (jump if zero (ZF set)) or "jnz" (jump if not zero (ZF clear)) conditional jump instruction.

Quote
like wise would this test for 3:
test ax, 3 - testing to see if 00000011 is set?

Yes. But you have to understand that it will test if either the first bit (01) or the second bit (10) or both (11) are set. Any of these three states would cause "test" to tell you that the number you tested for is "set" - if you test for multiple bits like this, the test instruction tells you whether at least one of the bits is set.
Title: Re: How does the test instruction work?
Post by: ThatGuy22 on December 15, 2010, 07:12:40 PM
Ok, thank you this was exactly what I was looking for.
Title: Re: How does the test instruction work?
Post by: JoyceTruitt on October 10, 2019, 02:44:16 PM
Nice One
Title: Re: How does the test instruction work?
Post by: fredericopissarra on October 10, 2019, 11:48:45 PM
I was wondering how the test instruction works, I know it does almost the same thing as and.

The only difference is that "test" only sets the flags (you're primarily interested in the Zero Flag (ZF) here) while "and" sets the flags (ZF) as well as the destination operand.
Just a tiny correction... TEST is, indeed AND affecting only the flags, but ALL arithmetic/logic related flags are affected... ZF, SF and PF are set/reset depending on the result, and CF=OF=0. The AF flag is undefined.
Title: Re: How does the test instruction work?
Post by: adanisch on October 23, 2019, 01:49:06 AM
An ordinance is informed for the enhancement of the goals for the humans. It is parked for the effectiveness of the writemypapers.org (https://www.toptenwritingservices.com/writemypapers-org-review/) for all notified items for the humans. The chance is diffused for their forms for the brisk paces and all challenges for the humans. it is signed for the reforms for the manners for the punctuation for the targeted and all elements for the able men and women of the area of the west.

Joyce did you intentionally choose an anagram of "juicy totter"?
What's going on with this project, is it dead? Why are there no updates since Jan 2018?

Update, I found a pulse: https://repo.or.cz/nasm.git