AS · Practice questions · Assemblers, compilers and interpreters

Compile or interpret?

Six original Cambridge-style questions on language translators, with mark-scheme 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

Match the translator to the job.

01
Explain
[2 marks]

Explain why an assembly language program needs to be translated by an assembler before it can be executed.

  • The processor can only execute machine code (binary instructions). ✓
  • The assembler converts each mnemonic (and its operand / symbolic address) into the equivalent machine code instruction. ✓
02
Explain
[4 marks]

Describe how a compiler and an interpreter differ in the way they translate a high-level language program.

  • A compiler translates the whole program before it is executed; an interpreter translates and executes one statement at a time. ✓
  • A compiler produces an executable file (object code); an interpreter does not, so the program is translated each time it is run. ✓
  • A compiler reports all errors at the end of compilation; an interpreter stops at the first error. ✓
  • Compiled code executes faster than interpreted code. ✓
03
Explain
[3 marks]

Give three benefits of using an interpreter while a program is being developed.

  • The program can be run without translating the whole of it first, so it can be tested as it is written. ✓
  • Execution stops at the line with the error, so errors are easy to locate. ✓
  • The error can be corrected and the program continued / re-run immediately; no need to recompile the whole program. ✓
04
Apply
[3 marks]

A software company is about to release a finished game to customers. Justify the use of a compiler for the release.

  • The compiler produces an executable file, so customers do not need a translator to run the game. ✓
  • The source code is not distributed, so it is protected from being copied or modified. ✓
  • The compiled game executes faster, which matters for a game. ✓
05
Explain
[3 marks]

Java programs are partially compiled and partially interpreted. Describe how a Java program is translated and executed.

  • The source code is compiled into bytecode (intermediate code). ✓
  • The bytecode is given to / run on the Java Virtual Machine (JVM) on the target computer. ✓
  • The JVM interprets the bytecode into the machine code of that computer as it executes, so the same bytecode can run on different platforms. ✓
06
Analysis
[2 marks]

A loop body of 3 statements is executed 1000 times. Explain why this program would run much faster compiled than interpreted.

  • A compiler translates the 3 statements once, before the program runs. ✓
  • An interpreter translates the statements every time they are executed, so 3 × 1000 = 3000 translations are carried out during execution. ✓

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.