Page 1 of 1

Opcode xor reg8, reg8

Posted: Sat Nov 08, 2008 8:28 am
by sebihepp
Hello,

on www.sandpile.org I found two versions of the opcode.
One is 0x30 and the other is 0x32. But what's the difference?
I think they are the same. Only the Value of the Mod R/M Byte has to
be switched.

TIA Sebihepp

Re: Opcode xor reg8, reg8

Posted: Sat Nov 08, 2008 9:57 am
by Combuster
The difference is just what you said. The thing is, all basic ALU operations have at least two forms:
OP dest, reg
OP reg, src
where dest and src can be any effective address, which includes various memory accesses, constants, and registers.
You can therefore use two register operands, but not two memory operands. If you do use the memory operand then you'll need to select the correct opcode from the one telling that either the parameter is read-only (the register is updated) or the one who says its read+write (and thus memory is updated)
In C (spot the difference):

Code: Select all

int register temp;
//add rm, reg
*addr += temp;
//add reg, rm
temp += *addr;
Hence you can use the first opcode and tell it to use reg2 as the register operand, and reg1 as the RM operand
The same goes for the second opcode, with the reg1 as the register operand and reg2 as the RM operand:
[XOR dest,reg] [RM is a register, reg2, register is reg1]
[XOR reg,src] [RM is a register, reg1, register is reg2]

Re: Opcode xor reg8, reg8

Posted: Sat Nov 08, 2008 1:43 pm
by sebihepp
Thanks for your answer. I just asked, because it is the first time I see two different opcodes
for exactly the same. But after reading your description it is all clear.

thanks again. Sebihepp

Re: Opcode xor reg8, reg8

Posted: Tue Nov 11, 2008 5:40 am
by jal
sebihepp wrote:it is the first time I see two different opcodes for exactly the same
There's more, since the x86 has some special opcodes for some basic instructions using ax/al as destination, but you can use the normal opcodes specifying ax/al as destination as well (but these are 1 byte longer).

The old A86 assembler used the different opcodes for the same instructions to watermark its output, in case anyone produced some commercial software without a licence.


JAL

Re: Opcode xor reg8, reg8

Posted: Tue Nov 11, 2008 6:05 pm
by Love4Boobies
I'm not sure how that would work. What's the benefit?