Why was NOP assigned to 0x90 in x86 assembly?
Asked Answered
U

1

13

Why was nop assigned to 0x90 on intel x86 assembly?

Intuitively I would expect that 0x00 would map to nop (which is also xchg eax, eax at intel x86) as it is the case for ARM A32 and some other architectures.

Unready answered 1/5, 2019 at 19:54 Comment(0)
K
17

0x00000000 is not actually NOP on ARM A32 though it behaves like one; it's actually andeq r0, r0, r0 whereas a real NOP is 0xe1a00000 (mov r0, r0). It's a rather bad idea to have the NUL byte be a NOP because that makes every empty memory region a free NOP slide, greatly increasing the risk for attacks. Modern architectures generally try to make all zeroes be a break instruction or similar to avoid this attack vector. For example, ARM A64 makes 0x00000000 a permanently undefined instruction udf 0.

0x90 is actually just one instruction of the 0x90 + r opcode family which stands for xchg r32, eax. eax is register 0, so 0x90 stands for xchg eax, eax which is a NOP. In long mode, 0x90 is special cased not to zero out the high 32 bit of rax to keep its function as a single byte NOP.

Kilovoltampere answered 1/5, 2019 at 20:19 Comment(1)
The good old 6502 viewed 0x00 as the BRK instruction. So it is not that recent.Extenuate

© 2022 - 2024 — McMap. All rights reserved.