Bug in TC2.0 Optimization

D'Arcy J.M. Cain darcy at druid.uucp
Mon Apr 29 21:31:11 AEST 1991


In article <1991Apr28.220249.1 at cc.helsinki.fi> wirzenius at cc.helsinki.fi writes:
>In article <1991Apr22.130418.8079 at uni-paderborn.de>, higgins at uni-paderborn.de (Frank Westheider) writes:
>> In Assembly-Mode there will be
>>     xor dx,dx
>> generated, but dx has never been loaded !
> [...]
>Since the result is 1 if and only if the operands are different, xoring
>a value with itself is identical to 0, regardless of the value of the
>operand. So the assembler statement sets dx to 0. Why didn't they just
>do it explicitly? Maybe this method is faster, smaller, or has some
>other virtue.

One of the skills of being an assembler programmer is to know the tricks
to speed up your program.  In the above case it is extremely obvious where
the savings happen.  If you do:
     mov dx, 0
you will get the same result but you need an extra 2 bytes to store the
zero in the code stream and you also need an extra memory fetch to get
it, 2 fetches on the 8088.  Another other way to zero a register is:
     sub dx, dx
which if I remember correctly uses the same number of cycles (2) as the
xor command but has some difference in flag handling on the 386.

-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   There's no government
Toronto, Ontario, Canada           |   like no government!
+1 416 424 2871                    |



More information about the Comp.lang.c mailing list