Are x86 opcodes arbitrary?

2019-05-07 15:19发布

Are x86 op codes arbitrary?

Is there a reason that hlt is 0xf4 and the nop is 0x90?

1条回答
神经病院院长
2楼-- · 2019-05-07 16:11

Very early versions of this architecture (8008,8080) were implemented using extremely small numbers of transistors/logic gates.

At that time, I'm sure the designers chose opcodes and instruction formats in ways that were easy to decode (e.g., smallest number of gates). The instructions tended to be simple, and regular in format.

(I know I did this designing a 16 bit CPU back in the 1970s. Intel might have done a better job but they were always in a hurry. My CPUs insisted that 4 bit opcodes 0000 and 1111 were invalid and caused a trap; this prevented data from being executed by accident in most cases because integral values tend to be all zeros or ones in their top bits).

Success and competition demands evolution and addition of new features. There is constant pressure to invent/add new instructions that enable the CPUs to do things faster and better: floating point, 32 bit data, more registers, SIMD operations, encryption, ...

As new generations of processors came, with larger transistor budgets, two things happened as designers tried to add new instructions:

  • The existing instruction set already defined a bunch of patterns, and these patterns could not be changed. So, designing new opcode, instruction formats and operands, had to be shoehorned into the "holes" in the instruction set. This forced peculiar combinations of bits for various instructions
  • The availability of more transistors meant that decoding complex bit patterns was not such an issue, so choosing strange bit combinations and decoding them was straightforward.

Repeat this process through a dozen generations of CPU until you reach modern times, with many-billion transistor chips. Now the instructions added get more exotic, and the patterns get more complex. It can look arbitrary; it isn't, but it isn't cleanly designed either.

What modern x86 chips do with instruction formats is pretty stunning, yet it works.

查看更多
登录 后发表回答