Consider a new instruction named branch-on-bit-set (mnemonic bbs). The instruction “bbs reg, pos, label” jumps to label if bit in position pos of register operand reg is one. A register is -bits wide and the bits are numbered to bit in position being the least significant. Consider the following emulation of this instruction on a processor that does not have bbs implemented.
Branch to label if temp is non-zero. The variable temp is a temporary register. For correct emulation, the variable mask must be generated by
View worked solution
Answer: A
The bbs reg, pos, label (branch-on-bit-set) instruction branches to label if the bit at index pos of register reg is .
The emulation performs a bitwise AND operation:
And branches if temp is non-zero.
For the emulation to work correctly:
- If the bit at index
posinregis , then must be non-zero. - If the bit at index
posinregis , then must be zero.
This requires the mask to have a binary at position pos and at all other bit positions. Such a mask is generated by shifting the value (represented in hex as 0x1) to the left by pos positions:
Therefore, the correct option is A.
Free practice · Your answers on this page are not saved.
