TopMyGrade

GCSE/Computer Science/OCR

2.5.2Translators: compilers vs interpreters; assemblers

Notes

Translators

OCR J277 Paper 2 sets 4–6 mark questions comparing compilers and interpreters, and asking what an assembler does. You need to know what each translator takes as input, what it outputs, and the practical trade-offs.

Why are translators needed?

A CPU only executes machine code (binary). High-level source code (Python, Java, C#) and assembly code must be translated before they can run.

Compiler

  • Input — the entire source-code file (high-level).
  • Output — a separate executable file containing machine code for a specific platform.
  • The translation happens once, before the program is run; after that the executable runs directly without the compiler.

Pros — fast execution after compilation; no need to ship the source code; cross-organisation distribution is easier.

Cons — slow develop-test cycle (recompile after every change); error messages list errors after the whole file is processed; produced executable is platform-specific.

Interpreter

  • Input — source code, line by line at run time.
  • Output — none (it executes each line directly).
  • Translation happens every time the program is run.

Pros — fast develop-test cycle (run code immediately); easier to debug because execution stops at the first error with the line number; same source can run on any platform that has the interpreter (Python, JavaScript).

Cons — slower execution than compiled code; the interpreter must be installed on the target machine; source code is exposed.

Assembler

  • Input — assembly language (mnemonics like MOV, ADD, JMP).
  • Output — machine code for a specific CPU architecture.
  • Almost a one-to-one mapping — each assembly instruction usually corresponds to a single machine-code instruction.

Used for embedded systems, device drivers, performance-critical or low-level code where direct hardware control is needed.

Comparison table

FeatureCompilerInterpreter
TranslatesWhole programOne line at a time
WhenOnce, before runEvery time the program runs
OutputExecutable machine codeNone — executes directly
Run speedFasterSlower
Develop-test speedSlower (recompile)Faster
Error reportingAfter the whole fileStops at first error
Source distributed?No (executable shipped)Yes (or interpreter ships with bytecode)
PortabilityCompiled per platformSame source, any platform with interpreter

Common OCR exam mistakes

  • Saying compilers are "always faster" — at run time, yes; but compiling itself is slow and must be redone after every change.
  • Forgetting that an assembler is for assembly language, not machine code already.
  • Mixing "interpreter translates line by line" with "interpreter executes line by line" — it does both: translate then execute, one line at a time.
  • Saying both produce machine code — interpreters do not write a separate executable.

AI-generated · claude-opus-4-7 · v3-ocr-computer-science-leaves

Practice questions

Try each before peeking at the worked solution.

  1. Question 14 marks

    Compiler vs interpreter

    State two differences between a compiler and an interpreter. [4 marks]

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-ocr-computer-science-leaves

  2. Question 24 marks

    Assemblers

    (a) State the input and output of an assembler. [2]
    (b) Give one situation in which assembly language is preferred over a high-level language. [2]

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-ocr-computer-science-leaves

  3. Question 36 marks

    Choosing a translator

    A development team is writing a commercial desktop application for sale to home users. Discuss whether a compiler or an interpreter would be more appropriate. [6 marks]

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-ocr-computer-science-leaves

Flashcards

2.5.2 — Translators: compilers vs interpreters; assemblers

7-card SR deck for OCR Computer Science (J277) — leaves batch 1 topic 2.5.2

7 cards · spaced repetition (SM-2)