Is the following instruction correct? What does it do?
andi $8,$0,0xFFFF
It is correct, but not very sensible.
It ANDs the contents of the zero register (all zeros)
with the immediate operand and puts the result in register $8
.
Of course, the result is all zeros,
regardless of the immediate operand.
XOR operation on Bits | ||||
---|---|---|---|---|
first operand | 0 | 0 | 1 | 1 |
second operand | 0 | 1 | 0 | 1 |
| ||||
result | 0 | 1 | 1 | 0 |
Filling a register with all zero bits is called clearing the register. Clearing a register is common, but the above instruction is not the best way to do it.
An exclusive OR is nearly the same as the more common OR (the inclusive OR) except that the result is zero when both operands are one.
Here is a description of the assembly language instruction.
The machine language for the instruction looks much the same
as the ori
and the andi
instruction.
xori d,s,const # register d is assigned # the bitwise XOR of immediate # operandconst
# and the contents of register $s. #const
is a 16-bit pattern, so # 0x0000 ...const
... 0xFFFF
The three operands of the instruction must appear in the correct order,
and const
must be within the specified range.
If the immediate operand in the assembly program is less than sixteen bits
(such as 0x2) the assembler expands it to sixteen.
If it is more than sixteen bits the assembler writes an error message.
Here are the two patterns, written both in bit patterns and in hex. Perform the bitwise XOR operation. (Do it with the bits, then re-write the answer in hex).