In the x86 instruction set, the bit with index 1 of the operation code can either be a direction bit, which indicates that it is the destination and source operands, or it can be a sign extension bit.
for example for add
00 /r ADD r/m8, r8and 02 /r ADD r8, r/m8
This bit differs r/m, regfrom reg, r/mfor the same mnemonics81 /0 id ADD r/m32, imm32vs 83 /0 ib ADD r/m32, imm8
full (bit 1 cleared) vs immediate with extended sign (bit 1 set)
I am wondering what is the easiest logical way to determine which of these cases it is. Is there a way to check, in addition to checking the operation codes of commands and comparing them, to find out what it is (for options for expanding the sign or direction of commands)? There are also instructions that ignore this bit, but since it is set to 0, it does not matter.
UPDATE: It turns out that for write errors (this is exactly what my code was intended for), reg-> r / m always takes place, because the r / m-> reg instruction will never cause a write error. But any information will still be useful if someone encounters a similar problem.
source
share