You can use the same C expression for both operands, or different expressions. A digit in constraint is allowed only in an input operand and it must refer to an output operand. Only a digit in the constraint can guarantee that one operand will be in the same place as another. The mere fact that foo is the value of both operands is not enough to guarantee that they will be in the same place in the generated assembler code. Of course, since the register for operand 1 is not even mentioned in the assembler code, the result will not work, but GNU CC can't tell that.
Some instructions clobber specific hard registers.
But it is valid no matter what the machine. This will cause GNU CC to not keep memory values cached in registers across the assembler instruction. The GNU assembler allows semicolons and most Unix assemblers seem to do so. The input operands are guaranteed not to use any of the clobbered registers, and neither will the output operands' addresses, so you can read and write the clobbered registers as many times as you like. This assumption may be false if the assembler code actually consists of more than one instruction.