Most Significant Bits
This week I think I fixed irregular behavior in the x64 instruction encoding register selction of DynASM. I think it'll be a fun story to share, so I thought it'd be time to blog. The astonishingly irregular thing about x64 instruction encoding is that it is mostly very regular. Ignoring for the moment instruction prefixes and constants, an x86 instruction consists of two bytes, one for the instruction proper, and one for it's two operands. Take for example the addition of two registers: +-----------------+ | add | eax, ecx | +-----------------+ | 0x01 | 0xc8 | +-----------------+ We take the instruction byte as given. It is the second byte that concerns me because it determines which operands to use and how. Like a good CISC architecture, the x86 supports a number of addressing modes , meaning that a register can be used as a value but also as a (part of a) pointer . One of the reasons C does pointer arithmetic so freely is that this reflects the nature of the