Question 4

AQA Computer Science June 2020 Paper 1GCSE13 marks

On the specification

4.1
3.2 Programming
4.2
3.2 Programming
4.3
3.2 Programming
4.4
3.4 Computer systems
4.5
3.4 Computer systems
4.6
3.1 Fundamentals of algorithms3.2 Programming
Question text

4 The algorithm shown in Figure 3 is used to check if the start of an instruction for a particular assembly language is valid. The string representation of the assembly language instruction is stored in the variable instr Characters in the string are indexed starting at zero. For example instr[2] would access the third character of the string stored in the variable instr Figure 3 code ← '' i ← 0 WHILE instr[i] ≠ ':' AND i < 4 code ← code + instr[i] i ← i + 1 ENDWHILE valid ← False IF code = 'ADD' OR code = 'SUB' OR code = 'HALT' THEN valid ← True ENDIF 4.1 Shade one lozenge to show the most appropriate data type of the variable i in the algorithm in Figure 3. [1 mark] A Character B Integer C Real D String 4.2 State the data type of the variable valid in the algorithm in Figure 3. [1 mark] 4.3 State the final value of the variable valid in the algorithm in Figure 3 for the following different starting values of instr [3 marks] Value of instr Final value of valid ADD R0, R1 ADD: R0, R1 HALT 4.4 State what an assembly language program must be translated into before it can be executed by a computer. [1 mark] 4.5 State two reasons why a programmer, who can program in both high-level and low-level languages, would usually choose to develop in a high-level language rather than a low-level language. [2 marks] Reason 1 Reason 2 4.6 Develop an algorithm, using either pseudo-code or a flowchart, that: • initialises a variable called regValid to False • sets a variable called regValid to True if the string contained in the variable reg is an uppercase R followed by the character representation of a single numeric digit. Examples: • if the value of reg is R0 or R9 then regValid should be True • if the value of reg is r6 or Rh then regValid should be False You may wish to use the subroutine isDigit(ch) in your answer. The subroutine isDigit returns True if the character parameter ch is a string representation of a digit and False otherwise. [3 marks]