test eax, eax - why?



Hi everyone,
I'm trying to learn x86 assembly language, and in addition to reading
the necessary books, trying the programmes etc., I'm also compiling my
own example C code and comparing it with the resultant (Visual C++)
code.

One thing I tried was compiling the "infinite" while(1){ ... } loop. I
got something like this:

mov eax, 1
test eax, eax
je label2

this seems somewhat odd. I know that "test" does a bitwise and of eax
and eax, but in this case, the rest of the
instruction (je) is not carried out. Why bother with this at all? Or
have I got the wrong end of the stick?

TIA

Paul

.



Relevant Pages

  • Re: Goto Statements and C++ Compiler Optimizations
    ... I tried using the goto statement (I have a ... The I am only using the /Ox compiler option. ... test eax, eax ...
    (comp.lang.asm.x86)
  • Re: Linux X demo
    ... test eax, eax; ERROR ... my apologies for propagating this sloppiness. ... Linus Torvalds ...
    (alt.lang.asm)
  • Another PosEx Entry
    ... test eax, eax ... test edx, edx ... jle @NotFoundPop // Pattern was not found. ...
    (borland.public.delphi.language.basm)
  • Re: Need help to optimizing code snippet
    ... > As long as you can trash EAX and you can ... > test eax, eax ... > cmovz eax, edx ... > (if EAX was not zero) against zero and jumps if the result is zero. ...
    (comp.lang.asm.x86)
  • Re: Need help to optimizing code snippet
    ... > if(eax && edx) ... As long as you can trash EAX and you can ... test eax, eax ... either compares EAX's original value (if it was zero) or EDX's value ...
    (comp.lang.asm.x86)