System Software: Question 5
Syllabus 5.2
Priya is writing a new game in a high-level programming language. While she is still developing and testing the game, she runs her code through an interpreter, so that she can try out small changes immediately. Once the game is finished, she instead uses a compiler to produce a final version that she can sell to customers.
A separate, older utility program used elsewhere in the same games studio was originally written directly in assembly language, and needs an assembler to prepare it for the processor.
(a) State what an assembler translates a program from, and what it translates that program into. [1]
(b) Describe how a compiler translates Priya's finished game before it can be sold to customers. [2]
(c) Describe how an interpreter translates and runs Priya's code while she is still testing small changes during development. [2]
(d) State three differences between using a compiler and using an interpreter to run a program, and use them to explain why a compiler, rather than an interpreter, is the better choice for the final version of the game that Priya sells to customers. [4]
Show worked solution Hide worked solution
Worked solution
Part (a): What an assembler translates
An assembler translates a program written in assembly language, which uses short mnemonic
instructions such as ADD or LDA. Into machine code (object code), the binary instructions that
the processor can execute directly. [1 mark] for correctly stating assembly language as the
source and machine code/object code as the result.
Part (b): How a compiler translates Priya’s finished game
A compiler takes the entire source code of Priya’s finished game and translates all of it into object code (machine code) in a single pass, completed before the game is ever run. This produces a stand-alone executable file. Once this compiling process is complete, the resulting object code can be run directly by the processor whenever needed, without Priya’s original source code or the compiler itself needing to be present at that point. [2 marks]: [1] for stating that the whole program is translated in one go, before execution, [1] for stating that this produces a stand-alone object-code file that can be run without the compiler/source code present.
Part (c): How an interpreter translates and runs Priya’s code during development
An interpreter works completely differently: instead of translating the whole program first, it takes Priya’s source code one statement at a time, translates that single statement, and executes it immediately, before moving on to translate and execute the next statement. No separate, stand-alone object-code file is ever produced or saved; every time Priya wants to run her code while testing it, the interpreter (and her original source code) must be used again from the start. [2 marks]: [1] for stating that one statement is translated and then immediately executed before moving to the next, [1] for stating that no separate object-code file is saved, so the interpreter and source code are needed on every run.
Part (d): Compiler vs interpreter. The differences, and why a compiler suits the final sold game
There are several genuine differences between the two:
- What is translated, and when. A compiler translates the entire program in one go, before any of it is run. An interpreter translates and executes the program one statement at a time, as it runs.
- Error reporting. A compiler attempts to translate the whole program and then reports all the syntax errors it has found together, typically at the end of compilation. An interpreter stops as soon as it reaches the first error it meets, reporting only that one error; later errors in the program are not discovered until this first one is fixed and the program is re-run.
- Speed of execution vs. speed of development. Because a compiled program’s object code has already been fully translated, it runs directly and quickly with no further translation needed. An interpreted program must be translated again, statement by statement, on every single run, so it executes more slowly, although being able to test small changes immediately, without waiting for a full compilation first, can make an interpreter convenient during development.
- Portability of the resulting code. A compiler’s object code is specific to the type of processor (and often the operating system) it was compiled for, and must be recompiled from the source code to run on a different type of processor. Source code run through an interpreter, by contrast, can run on any platform that has a copy of a suitable interpreter installed, without needing a separately compiled file for each platform.
For the final version of the game that Priya sells to customers, a compiler is the better choice: customers receive a fast-running, ready-to-execute object-code file, and do not need a copy of the compiler, the interpreter, or Priya’s original source code installed on their own computer just to play the game. It is also an advantage that any syntax errors will already have been found and fixed by Priya herself while compiling and testing the finished game, rather than appearing partway through a customer’s use of it, as could happen with a program still being translated statement-by-statement by an interpreter. [4 marks]: [1] each for up to three correctly stated differences (max 3), [1] for correctly explaining why this makes a compiler the better choice for the version sold to customers.
Final answers
- (a) An assembler translates assembly language into machine code (object code).
- (b) A compiler translates the whole program into object code before it runs, producing a stand-alone executable.
- (c) An interpreter translates and executes one statement at a time as the program runs, with no saved object-code file.
- (d) Differences: whole-program vs statement-by-statement translation; all errors reported together vs stopping at the first error; faster execution of compiled object code vs slower interpreted execution; object code is processor-specific vs interpreted source code being more portable. A compiler suits Priya’s sold game because it gives customers a fast, ready-to-run program with no compiler/interpreter/source code needed, and with errors already fixed before sale.