Log in

View Full Version : Dont quite understand what this inst is doing


Flack
June 16th, 2004, 22:40
Hello,

Here is the part of code I need help with:

Code:

0050B311 /$ 8B4424 08 MOV EAX,DWORD PTR SS:[ESP+8]
0050B315 |. 56 PUSH ESI
0050B316 |. 85C0 TEST EAX,EAX
0050B318 |. 8BF1 MOV ESI,ECX
0050B31A 75 08 JNZ SHORT nbpro.0050B324


Now, when I get to line 50B311, an ASCII string from the stack is placed in EAX. My question is what exactly does TEST EAX,EAX do? Wont that always result in clearing the zero flag? Isnt that what happens when you TEST something with itself?

As you can probably tell from my question, I am quite new at this

Thanx for the help,
-Flack

evlncrn8
June 16th, 2004, 23:04
TEST - Test For Bit Pattern

Usage: TEST dest,src
Modifies flags: CF OF PF SF ZF (AF undefined)


Performs a logical AND of the two operands updating the flags
register without saving the result.


download a copy of helppc (google search)

bilbo
June 17th, 2004, 01:30
In your particular case, testing something (EAX) with itself means that, as soon as just one bit of EAX is set, the Zero Flag will be cleared.
E.g. testing the binary 0100 against 0100 will reset the Zero flag, but also testing 01100 or 01000 with itself.
The only way to have the zero flag set is to test a null value.
In other words, TEST EAX,EAX followed by JNZ xxx is equivalent to
IF (EAX not null) THEN jump xxx

Regards, Bilbo