Useless instructions

From Rosetta Code
Revision as of 03:46, 16 October 2021 by Puppydrum64 (talk | contribs) (Created page with "{{draft task}} ;Task Showcase an instruction or function built into the language, that is made redundant by another instruction already built into the language. It can be li...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Useless instructions is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task

Showcase an instruction or function built into the language, that is made redundant by another instruction already built into the language. It can be limited to a specific way that function is used, e.g. printing a null string, but try not to make it that obvious.



6502 Assembly

CMP #0 is nearly completely useless, as most 6502 instructions do this implicitly. It can be handy when you need to check equality to zero after a different register was altered, and in that scenario using PHP/PLP to save and restore the condition codes would be impractical, but these situations are few and far between.

<lang 6502asm>myLoop:

do stuff here

dex

cpx #0 ;this isn't needed since the zero flag will be set if x=0

bne myLoop ;if x != 0, jump back to myLoop</lang>

68000 Assembly

CLR.L Dn sets an entire 32-bit register to 0x00000000. However, MOVEQ #0,Dn does the same thing but faster. The only advantage CLR Dn has is that it can directly clear memory locations.

x86 Assembly

Originally, LOOP label was a one-line version of DEC ECX JNZ label, but even Intel now recommends to use the latter over the former, due to LOOP taking longer to execute than DEC ECX JNZ on the 486 and beyond. Most compilers don't use LOOP anymore either. An explanation can be found here.