View Full Version : opcode encodings

March 4th, 2011, 09:01

I were reviewing some code, and noted this odd thing:

why on certain 2-byte instructions the 'to' register is swapped with respect of the 'from' register?

adc eax, ecx == 11C8 (the 'expected' one)
sbb eax, ecx == 11C1

what's the point/need of swapping the source/destination bytes - apart angering people?

---self answered: I forgot that fucking swap bit, i were cross-checking things with olly which enforce on certain instructions the bit and on some others not (!), and I werent remebering/checking/lookit at it, at first. bah bah... all is fine now.

March 5th, 2011, 03:50
(Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 2B, A.2.1)

E* - A ModR/M byte follows the opcode.
G* - The reg field of the ModR/M bytes selects a general register.

13 C1 adc eax,ecx (Gv, Ev)
11 C8 adc eax,ecx (Ev, Gv)
1B C1 sbb eax,ecx (Gv, Ev)
19 C8 sbb eax,ecx (Ev, Gv)

(v.2A, T2-2)
(76 - Mod, 543 - Reg, 210 - R/M)
11 000 001 C1 Eax, Ecx
11 001 000 C8 Ecx, Eax


March 5th, 2011, 05:54
yep, it's on the end of N-Z manual

in truth, I did start to madden, with doubts over my IA32 knowledge ...until i did remember that such damn bit exist *AND* the observed that OllyDBG sometime turns it on, when assembling instructions

(i were cross-checking my code-generated assembly with OllyDbg, rewriting my istructions there and wondering why some were different, totally forgetting it)