9618/12/O/N/24 question 8: worked solution (October/November 2024, paper 12)

Show as plain text

Cambridge AS Level Computer Science 9618 · 4.3 Bit manipulation Worked solution from the Processor Fundamentals Paper 1 Theory Fundamentals booklet, Part 3 of 3. Q36 9618/12/O/N/24 original Q8 Structured · 11 marks 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. Instructions ACC content IX content LDM #19, DEC ACC 18 20 LDD 23, ADD 19 40 20 LDI 25, INC ACC 5 20 LDR #21, LDX 2 15 21 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. Instructions ACC content LSL #2 0110 1000 ADD #5, AND #30 0001 1110 OR B11110010, INC ACC 1111 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 IDEA Follow each instruction one at a time, remembering that indirect and indexed addressing use a second address. TOTAL 11 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Craig'n'Dave. Tap the picture to open it on YouTube.