Re: test eax, eax - why?




spamtrap@xxxxxxxxxx wrote:
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?

I suspect you didn't turn optimizations on :-)
Either that, or you've got a really *bad* compiler. But this is such an
easy optimization, I'd have to guess that you didn't turn optimization
on. When you don't have optimization active, most compiler generate
pretty lame code.
Cheers,
Randy Hyde

.



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: C/C++ Compilers Optimization Failed
    ... I used C/C++ Compiler's Optimization. ... >> xor eax, eax ... I am shocked that C/C++ Compiler did not tune optimization very well ...
    (comp.lang.asm.x86)
  • Re: missing optimization?
    ... Both, function1 and function2, have duplicated ... > movl _data, %eax ... > subl 4, %eax ... > If compiler is *newer* than 2.95, then it puts the TEST opcode. ...
    (comp.os.msdos.djgpp)
  • Re: C/C++ Compilers Optimization Failed
    ... > xor eax, eax ... If you don't like the code generated by that compiler, ... And why are you complaining in an assembly language newsgroup about ... > (Optimization is not important YET!!) ...
    (comp.lang.asm.x86)
  • Re: compiler generated output
    ... > compiler to generate code which only uses 386 instruction). ... > Thus, while replacing mov/and with movzx, the jump is still there. ... mov eax, ... Software Optimization Guide for ...
    (comp.lang.asm.x86)