Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Remember that the bits that make up the instructions are not actually numbers - they are switches. i.e. each bit in the number turns on a section of the cpu, then that section of the cpu checks the next bit, and turn on the next part of the cpu, following it down till you get to the proper component that carries out the instruction.

So by having a pattern to your instructions you can optimize the layout of the CPU. XCHG AX,AX does exactly that, with no visible effect, but the action is carried out.

That was then.

These days CPUs compile machine language into microcode, so you can pick any number for the opcode. The microcode is still switches based on the bits, but you don't see that.



In fact, once the 486 hit, 0x90 was an explicit NOP (1 cycle instead of the 3 that an XCHG usually takes, won't stall the pipeline even if other stuff touches AX, etc.).

Similarly, on x64 0x90 is a true no-op, while stuff like XCHG EBX, EBX clears the upper 32 bits of the register.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: