Author Topic: How does the test instruction work?  (Read 5177 times)

Offline ThatGuy22

  • Jr. Member
  • *
  • Posts: 40
How does the test instruction work?
« 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.
« Last Edit: December 15, 2010, 05:36:59 PM by ThatGuy22 »

Offline cm

  • Jr. Member
  • *
  • Posts: 65
Re: How does the test instruction work?
« Reply #1 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.
C. Masloch

Offline ThatGuy22

  • Jr. Member
  • *
  • Posts: 40
Re: How does the test instruction work?
« Reply #2 on: December 15, 2010, 07:12:40 PM »
Ok, thank you this was exactly what I was looking for.

Offline JoyceTruitt

  • New Member
  • Posts: 1
Re: How does the test instruction work?
« Reply #3 on: October 10, 2019, 02:44:16 PM »
Nice One
« Last Edit: October 26, 2019, 07:00:06 AM by JoyceTruitt »

Offline fredericopissarra

  • Jr. Member
  • *
  • Posts: 55
Re: How does the test instruction work?
« Reply #4 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.

Offline adanisch

  • Jr. Member
  • *
  • Posts: 4
Re: How does the test instruction work?
« Reply #5 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 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

« Last Edit: October 23, 2019, 02:36:46 AM by adanisch »