Useless instructions: Difference between revisions
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...") |
Puppydrum64 (talk | contribs) m (it's ok if the "better" instruction was added later) |
||
Line 3: | Line 3: | ||
;Task |
;Task |
||
Showcase an instruction or function built into the language, that is made redundant by another instruction |
Showcase an instruction or function built into the language, that is made redundant by another instruction also 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. |
||
<br><br> |
<br><br> |
Revision as of 03:48, 16 October 2021
- Task
Showcase an instruction or function built into the language, that is made redundant by another instruction also 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.