Consider a new instruction named branch-on-bit-set (mnemonic bbs). The…

2006

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 32 bits wide and the bits are numbered 0 to 31, bit in position 0 being the least significant. Consider the following emulation of this instruction on a processor that does not have bbs implemented. temp¬reg & mask 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:

Answer: A. mask ← 0 x 1 ο posCorrect mask formula: mask = 1 << pos (i.e., 0x1 shifted left by pos) Step 1: Compute the mask as a single-bit value at the requested position: mask = 1 <<…

  1. A.

    mask ← 0 x 1 ο pos

  2. B.

    mask ← 0 x ffffffff ο pos

  3. C.

    mask ← pos

  4. D.

    mask ← 0 × f

Attempted by 28 students.

Show answer & explanation

Correct answer: A

Correct mask formula: mask = 1 << pos (i.e., 0x1 shifted left by pos)

  • Step 1: Compute the mask as a single-bit value at the requested position: mask = 1 << pos.

  • Step 2: Apply the mask to the register: temp = reg & mask.

  • Step 3: Branch to the label if temp is non-zero (i.e., the tested bit was 1).

Why this works: Shifting 1 left by pos produces a value with exactly one bit set at the desired position; ANDing isolates that bit.

Why the other mask expressions are incorrect:

  • Using 0xFFFFFFFF shifted left by pos generates many ones (a wide region of set bits) rather than a single-bit mask, so it does not isolate the single bit.

  • Using the numeric pos value itself does not create a mask; it yields small integers like 3 instead of the bit mask 0x8 for pos = 3.

  • Using a constant like 0xF is a multi-bit mask (bits 0–3), not a single-bit mask at the requested position.

Explore the full course: Isro

Loading lesson…