Cambridge AS Level Computer Science 9618 · 4.3 Bit manipulation

Q36 · 9618/12/O/N/24 Q8

Worked solution from the Processor Fundamentals Paper 1 Theory Fundamentals booklet, Part 3 of 3.

Q369618/12/O/N/24original Q8Structured · 11 marks
Question 8 from 9618/12/O/N/24

Worked solution

(a)

Run each set of instructions from the starting values ACC = 50 and IX = 20 (each set is run separately from these values).

Set 1: LDM #19 puts 19 in ACC. DEC ACC makes it 18. IX is unchanged at 20.

Set 2: LDD 23 loads the contents of address 23, which is 15. ADD 19 adds the contents of address 19, which is 25: 15 + 25 = 40. IX is still 20.

Set 3: LDI 25: address 25 holds 22, so go to address 22 and load its contents, which is 4. INC ACC makes it 5. IX is still 20.

Set 4: LDR #21 puts 21 in IX. LDX 2 uses address 2 + 21 = 23, which holds 15, so ACC = 15.

InstructionsACC contentIX content
LDM #19, DEC ACC1820
LDD 23, ADD 194020
LDI 25, INC ACC520
LDR #21, LDX 21521

ACC correct for set 1 [1]

ACC correct for set 2 [1]

ACC correct for set 3 [1]

ACC correct for set 4 [1]

IX column correct (20, 20, 20, 21) [1]

(b)(i)

Start each set with ACC = 10011010 (154 in denary).

Set 1: shift left 2 places, drop the two left bits and add two 0s on the right: 01101000.

Set 2: 154 + 5 = 159 = 10011111. AND with #30 (00011110) keeps only the bits where both are 1: 00011110.

Set 3: 10011010 OR 11110010 = 11111010. INC ACC adds 1: 11111011.

InstructionsACC content
LSL #20110 1000
ADD #5, AND #300001 1110
OR B11110010, INC ACC1111 1011

Set 1 correct [1]

Set 2 correct [1]

Set 3 correct [1]

(b)(ii)

An odd binary number always has a 1 in the least significant bit (LSB). [1]

Use a mask to keep only the LSB and clear all the other bits, then compare the result with 1. If it is equal, the number is odd. [1]

Instruction:

AND #1

The instruction AND B00000001 (or AND #1 or AND &01) [1]

KEY IDEAFollow each instruction one at a time, remembering that indirect and indexed addressing use a second address.
TOTAL 11 marks

Official mark scheme

Mark scheme for 9618/12/O/N/24 question 8
VIDEO
▶ Topic lesson

A lesson on this topic · by Craig'n'Dave. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.