Newsgroups: comp.lang.c Path: utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!lethe!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Subject: Re: Bug in TC2.0 Optimization Message-ID: <1991Apr29.113111.9047@druid.uucp> Organization: D'Arcy Cain Consulting, West Hill, Ontario References: <1991Apr22.130418.8079@uni-paderborn.de> <1991Apr28.220249.1@cc.helsinki.fi> Date: Mon, 29 Apr 91 11:31:11 GMT In article <1991Apr28.220249.1@cc.helsinki.fi> wirzenius@cc.helsinki.fi writes: >In article <1991Apr22.130418.8079@uni-paderborn.de>, higgins@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@druid) | D'Arcy Cain Consulting | There's no government Toronto, Ontario, Canada | like no government! +1 416 424 2871 |