AS · Practice questions · Shifts, masks and bit manipulation

Mask it, shift it.

Six original Cambridge-style questions on binary shifts and bit masking with the 9618 instruction set, with mark-scheme style solutions.

Original questions All questions on this page are original work, written in the Cambridge AS & A Level style. They are not from past papers. They test the same concepts and skills the syllabus rewards.
Keep these straight

Choose the right tool.

01
Recall
[3 marks]

Describe the difference between a logical shift, an arithmetic shift and a cyclic shift.

  • Logical: bits move left or right, zeros are introduced at the empty end and bits shifted out are lost. ✓
  • Arithmetic: the sign bit is preserved (in a right shift the sign bit is copied into the empty places), so signed numbers keep their sign. ✓
  • Cyclic: bits shifted out of one end are moved in at the other end, so no bits are lost. ✓
02
Calculate
[4 marks]

The ACC holds the unsigned value 00110101. Give the contents of the ACC after (a) LSL #2 and (b) LSR #3, each applied to the original value. State the effect of each shift on the denary value.

  • (a) 11010100. ✓
  • (a) 53 becomes 212: multiplied by 4. ✓
  • (b) 00000110. ✓
  • (b) 53 becomes 6: divided by 8 with the remainder lost (the bits 101 are lost). ✓
03
Calculate
[2 marks]

The 8-bit two's complement value 10011000 is shifted 2 places to the right using an arithmetic shift. Give the result in binary and in denary.

  • 11100110. ✓
  • −104 becomes −26 (divided by 4). ✓
04
Write
[3 marks]

Bit 3 of the byte at address STATUS switches on a pump. Write assembly language instructions, using the 9618 instruction set, to switch the pump on without changing any other bit.

  • LDD STATUS ✓
  • OR B00001000 (or OR #8 / OR &08) ✓
  • STO STATUS ✓
05
Write
[4 marks]

Bit 6 of the byte at address SENSOR is 1 when a door is open. Write assembly language instructions, using the 9618 instruction set, to jump to the label DOOROPEN if the door is open.

  • LDD SENSOR ✓
  • AND B01000000 (mask to keep only bit 6) ✓
  • CMP #0 ✓
  • JPN DOOROPEN (or CMP B01000000 then JPE DOOROPEN) ✓
06
Analysis
[3 marks]

The ACC holds 11010010. Give the contents of the ACC after XOR B00001111 and explain the effect of this mask.

  • 11011101. ✓
  • The four least significant bits are inverted (toggled). ✓
  • The four most significant bits are unchanged, because XOR with 0 leaves a bit as it is. ✓

Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.