AQA A-Level Computer Science 7517
Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation
Fundamentals of Data Representation
Fundamentals of Computer Systems
Fundamentals of Computer Organisation and Architecture
Fundamentals of Communication and Networking
Consequences of Uses of Computing
Systematic Approach to Problem Solving
Fundamentals of Databases
Big Data
Fundamentals of Computer Systems
Types of program translator
- 2 things to know
- Paper 2
Overview
Recall questions on assemblers, compilers and interpreters, when each is the right choice, and why some compilers emit bytecode for a virtual machine.
What you need to know
Answer each one before you reveal it.
What is the difference between source code and object code?
Questions from this subtopic
Each one with the model answer underneath.
- 1
Understand the role of an assembler.
Model answer
An assembler translates assembly language source code into machine code. It replaces each mnemonic with the corresponding binary opcode, converts operands into the correct binary form for the addressing mode used, works out the actual addresses that labels stand for, and outputs the machine code ready to be loaded and run. Translation is normally one assembly instruction to one machine instruction.
- 2
Understand the role of a compiler.
Model answer
A compiler translates an entire high-level language program into machine code (or into an intermediate code) before execution. It checks the whole program for syntax errors and reports them together, and typically works through lexical analysis, syntax analysis, semantic analysis, code generation and optimisation. The output is a separate object or executable file that can be run repeatedly without the compiler or the source code being present.
- 3
Understand the role of an interpreter.
Model answer
An interpreter takes a high-level language program and translates and executes it one statement at a time, in the order the statements are reached at run time. It produces no separate executable file, so the source code and the interpreter must both be present every time the program runs, and a statement inside a loop is re-analysed on every pass.
- 4
How does compiling a program differ from interpreting it?
Model answer
A compiler translates the whole program once, before it runs, and produces an executable file; an interpreter translates and runs the program statement by statement, each time it is run, and produces no file. A compiler reports all the errors it finds at the end of translation, and the program cannot run until they are fixed; an interpreter stops at the first error it reaches, so later errors are only found when execution gets that far. Compiled code runs faster, because translation happens once and the running program is native machine code, whereas an interpreter re-analyses each statement every time it is executed. Compiled code hides the source, because only the machine code is distributed; interpreted code must be distributed as source unless it is obfuscated. Compiled output is machine specific and must be recompiled for a different processor, while an interpreted program will run anywhere the interpreter exists.
- 5
Describe a situation in which compilation is the appropriate choice, and say why.
Model answer
Distributing finished commercial software to customers. The program will be run many times by people who will never edit it, so paying the cost of translation once, at the developer's end, buys fast execution every time it is run. The customer needs no compiler and no source code, the machine code is hard to copy or alter, and the developer's source stays private.
- 6
Describe a situation in which interpretation is the appropriate choice, and say why.
Model answer
Developing and testing a program, or teaching programming. The programmer changes the code constantly and wants to run it immediately, and waiting for a full recompilation after each small edit wastes time. An interpreter also stops at the offending statement, which makes it easy to see where the fault is, and often allows statements to be tried out interactively, one at a time. Interpretation is also appropriate for a script that must run unchanged on many different types of machine.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Fundamentals of Computer Systems, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.