14.1. Preventing ESP as SIB Index
In x86, the ESP register cannot be used as an index in SIB addressing. The encoding
index=100 (which would be ESP) instead means "no index register." Traditional
assemblers catch this as a runtime error. We catch it at compile time:
The NonSPReg type is defined as a subtype of Reg that excludes ESP:
#check NonSPReg -- Registers excluding ESP
#check NonSPReg.EAX -- Valid
#check NonSPReg.ECX -- Valid
#check NonSPReg.EBX -- Valid
-- NonSPReg.ESP doesn't exist!
The MemSpec.regIdx constructor requires a NonSPReg for the index:
#check MemSpec.regIdx EBX (.ECX) Scale.S4
-- This would NOT compile:
-- #check MemSpec.regIdx EBX (.ESP) Scale.S4
-- Error: NonSPReg has no constructor ESP