- Understand why programs must be translated before the processor can run them
- Describe the purpose of compilers, interpreters and assemblers
- Choose a suitable translator for a programming situation and justify the choice
- I can state that machine code is the binary instruction code executed by the CPU
- I can compare compiled and interpreted programs using speed, error reporting and distribution
- I can identify when an assembler is needed
- I can explain my answer using scenario evidence rather than one-word labels
Answer before the lesson begins. These check prior knowledge — it's fine if you're unsure.
1. Which option best describes machine code?
2. Why do programmers usually write in high-level languages such as Python or Java?
3. What must happen before source code can be executed by the processor?
Key vocabulary
Translators
Why translation is needed
Programmers usually write programs in languages that are practical for humans. Python, Java and similar high-level languages use words, symbols and structures that are easier to read than long strings of binary. The processor, however, does not understand high-level source code directly. A CPU executes machine code: binary instructions designed for that processor. A translator is therefore needed to convert source code into a form the computer can run.
Translation is part of the software development process. It allows a programmer to write clear source code, then have specialist software convert it into lower-level instructions. Different translators are used in different situations. At National 5, the three important types are compiler, interpreter and assembler.
Compilers
A compiler translates the whole source program before the program is executed. If the compiler finds syntax errors, the program will not compile successfully until the errors are fixed. When compilation succeeds, the output may be object code or an executable program that can be run without translating the original source code again each time.
Compiled programs are usually fast to run because the translation work has already happened. They are also convenient for distribution because users can be given an executable file rather than the original source code. This can help protect the source code. A disadvantage is that compilation can take time, and error messages may be produced after the compiler checks the program rather than exactly at the moment an instruction is reached during execution.
Interpreters
An interpreter translates and executes a program one instruction at a time while the program is running. It does not normally create a separate executable file. This is useful during development because the programmer can run code quickly, test small sections and see where an error occurs. Languages commonly used in classrooms, such as Python, are often described as interpreted because pupils write source code and run it through an interpreter.
The main disadvantage is speed. Because translation happens during execution, interpreted programs can run more slowly than compiled programs. The interpreter program must also be available on the computer that runs the source code. This makes interpreters excellent for learning, experimenting and debugging, but not always the best choice where maximum execution speed or easy distribution is the main requirement.
Assemblers
Assembly language is a low-level language that uses short mnemonic codes such as LDA, ADD or STA instead of pure binary. These mnemonics are easier for humans to read than machine code, but they are still closely linked to the processor's instruction set. An assembler translates assembly language into machine code.
Assembly language is used when a programmer needs very close control of hardware or processor instructions. It is less portable and harder to write than a high-level language, but it can be useful in embedded systems, device drivers and performance-critical routines. In an exam, if the source code is assembly language, the correct translator is an assembler.
Choosing the right translator
Exam questions often ask for a translator to match a scenario. A development situation with frequent testing and debugging may point towards an interpreter. A finished application that should run quickly and be distributed to users may point towards a compiler. Assembly language always points towards an assembler. Strong answers explain the reason, not just the name. For example: "A compiler is suitable because the finished game should run quickly and users do not need to see the source code."
| Translator | Input | How it works | Useful when... |
|---|---|---|---|
| Compiler | High-level source code | Translates the whole program before execution | A finished program needs fast execution or distribution |
| Interpreter | High-level source code | Translates and executes one instruction at a time | A program is being tested, debugged or developed interactively |
| Assembler | Assembly language | Translates assembly mnemonics into machine code | Low-level processor instructions or hardware control are needed |
Worked examples
A company has finished a desktop game. The game should run quickly and customers should not need the source code. Which translator is suitable?
A programmer is learning Python and wants to test small changes often while fixing syntax errors.
A program is written using processor mnemonics such as LDA, ADD and STA. Which translator is required?
A small team is building a program. During development they want to run the program after every few lines of code. Later, they want to release the final version to users so it runs quickly and users do not need the source code.
Answer the following:
- Which translator is most useful during development?
- Which translator is most useful for the final released version?
- Give one reason for each choice.
- An interpreter is useful during development.
- A compiler is useful for the final released version.
- The interpreter helps with quick testing and debugging. The compiler can produce a faster executable and means users do not need the source code.
For translator questions, underline the clue words. Whole program, executable, fast running, protect source code usually points to a compiler. Line by line, testing, debugging, immediate feedback usually points to an interpreter. Assembly language or mnemonics points to an assembler. A two-mark answer normally needs the translator and a reason linked to the scenario.
Questions 1-5 are auto-checked. Questions 6-9 are self-marked — write your answer, then reveal the model answer to check your work.
1. Which translator converts the whole source program before it is executed? TYPE 1
2. Which translator is most closely linked to line-by-line execution? TYPE 1
3. Which translator is required for assembly language? TYPE 1
4. Which is a likely advantage of a compiled program? TYPE 1
5. Which situation best matches an interpreter? TYPE 1
6. Describe two differences between a compiler and an interpreter. TYPE 2
7. Explain why a programmer might prefer an interpreter while developing a new program. TYPE 2
8. A company wants to distribute a finished program to many users. The program should run quickly and users should not need access to the source code. Recommend a translator and justify your answer. TYPE 3
9. A developer writes a short routine using assembly language to control hardware directly. Identify the translator required and explain its purpose. TYPE 3
Suggested timing: 60 minutes. Warm up 6 min; vocabulary 6 min; notes 20 min; worked examples 10 min; now you try 5 min; task set 13 min.
Key misconception to address: Pupils often memorise one-word definitions but struggle to match the translator to a scenario. Keep asking: is the clue speed/distribution, debugging/testing, or assembly language?
Live demo suggestion: Show a tiny Python syntax error and run it to discuss interpreter feedback, then contrast this with the idea of compiling a finished program into an executable.
Extension question: Some languages use more than one translation stage, such as compiling to bytecode and then running on a virtual machine. Why might that improve portability?
SQA command words covered: "state", "identify", "describe", "explain", "recommend", "justify".