Hi,

I was wondering if the second operand of every assembly instruction is read-only? I need to know this for sure for an automatic optimization algorithm I'm working on. As far as I know there is no instruction that directly changes the source operand but I'm just asking you experts...

Thanks!
Posted on 2003-11-18 14:08:18 by C0D1F1ED
Are you talking about only memory operands. If you are talking about memory then I believe you're right. Registers are a different story with XCHG and others like it.
Posted on 2003-11-18 14:33:41 by donkey

Are you talking about only memory operands. If you are talking about memory then I believe you're right. Registers are a different story with XCHG and others like it.


Of course, many assemblers accept "xchg reg,mem" as well. I suspect the OP was talking about assembly source code (rather than binary machine code) as the whole concept of "second operand" doesn't make much sense at the machine code level.

Also, the cmpxchg, xadd, and other such instructions mess with multiple operands.
Cheers,
Randy Hyde
Posted on 2003-11-18 15:09:59 by rhyde
I totally forgot about the xchg instructions... Thanks!
Posted on 2003-11-19 02:41:39 by C0D1F1ED
Trying to make complete list:

XCHG
XADD
CMPXCHG
CMPXCHG8B

Any other?
Posted on 2003-11-19 14:09:59 by MazeGen
Of course, if the second operand is the same as the first, they will both be changed.

Which brings to mind that an address register will change if it appears as the destination register.
Posted on 2003-11-19 15:41:55 by tenkey

Of course, if the second operand is the same as the first, they will both be changed.

That's no problem. I just mark the destination as modified, and it will be known for all consecutive instructions.

It only has to be conservative. It's alright to mark a destination operand as modified even if it's not (like jmp eax). It will just make the optimizer a little less effective (got average 10% instruction eliminated at the moment). But the xchg instructions would have caused trouble if I didn't detect them...

Thanks all!
Posted on 2003-11-20 03:58:52 by C0D1F1ED
Eh, a mistake. About CMPXCHG, a source operand SRC is never used as a destination. I think a mnemonic of this instruction is not much correct (where is the exchange?).

CMPXCHG r/m, r operation:


(* accumulator = AL, AX, or EAX, depending on whether *)
(* a byte, word, or doubleword comparison is being performed*)
IF accumulator = DEST
THEN
ZF <- 1
DEST <- SRC
ELSE
ZF <- 0
accumulator <- DEST
FI;
Posted on 2004-01-03 15:38:50 by MazeGen