Opcode xor reg8, reg8

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
sebihepp
Member
Member
Posts: 197
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Opcode xor reg8, reg8

Post 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Opcode xor reg8, reg8

Post 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]
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
sebihepp
Member
Member
Posts: 197
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: Opcode xor reg8, reg8

Post 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
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Opcode xor reg8, reg8

Post 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
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Opcode xor reg8, reg8

Post by Love4Boobies »

I'm not sure how that would work. What's the benefit?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply