Useless instructions: Difference between revisions

no edit summary
m (it's ok if the "better" instruction was added later)
No edit summary
Line 18:
=={{header|68000 Assembly}}==
<code>CLR.L Dn</code> sets an entire 32-bit register to 0x00000000. However, <code>MOVEQ #0,Dn</code> does the same thing but faster. The only advantage <code>CLR Dn</code> has is that it can directly clear memory locations.
 
=={{header|8086 Assembly}}==
<code>xor ax,ax</code> (or any other data register) takes fewer bytes to encode than <code>mov ax,0</code> and achieves the same result. The only difference is that <code>mov ax,0</code> doesn't set the flags, which can be used to the programmer's advantage when sequencing operations.
 
=={{header|x86 Assembly}}==
Originally, <code>LOOP label</code> was a one-line version of <code>DEC ECX JNZ label</code>, but even Intel now recommends to use the latter over the former, due to <code>LOOP</code> taking longer to execute than <code>DEC ECX JNZ</code> on the 486 and beyond. Most compilers don't use <code>LOOP</code> anymore either. An explanation can be found [https://stackoverflow.com/questions/35742570/why-is-the-loop-instruction-slow-couldnt-intel-have-implemented-it-efficiently here.]
 
=={{header|Z80 Assembly}}==
<code>xor a</code> is shorter than <code>ld a,0</code>. The latter doesn't clear the zero or carry flags, which is often useful. But if the flags aren't needed for an upcoming branch, call, or return, <code>xor a</code> is better.
1,489

edits