Teachers' Portal  /  IGCSE Computer Science 0478  /  Software  /  Assemblers, compilers and interpreters
Lesson pack · IGCSE Computer Science 0478 · 4.2 · IGCSE

Assemblers, compilers and interpreters

All at once, or line by line. Every program has to become machine code before the processor can run it.

Student lesson Lab, full screen
At a glance

The shape of the lesson

Topic
Software
Syllabus reference
Cambridge IGCSE Computer Science 0478, 4.2
Level
IGCSE
Duration
45 minutes, lab-led; stretches to a 60 minute block (see the contingency notes)
Position in topic
Lesson 5 of 6 in Software; follows High-level and low-level languages; leads into Integrated development environments (IDEs)
Central model
Fig. 1: a compiler translates the whole program into an executable file; an interpreter translates and runs one line at a time
Cooperative structure
Assessment
Stage 1 check and the exam-style plenary from the student lesson, plus the worksheet as the exit task
Learning objectives

By the end of the lesson, learners can

Section by section
  • Three translators: Which translator you need depends on the language the source code is written in.
  • How errors are reported: Here is a short program with mistakes on lines 2 and 4.
  • Compiler or interpreter?: Both have strengths.
Key points to leave on the board
  • Assembler: assembly language to machine code.
  • Compiler: whole high-level program at once; executable file; error report for the whole code.
  • Interpreter: translates and executes line by line; stops at the first error.
  • Use: interpreter while developing; compiler for the final program.
The core visual model

One picture every idea returns to

A translator turns source code into machine code. An assembler translates assembly language. A compiler translates the whole high-level program at once before it is executed, producing an executable file; if there are errors it gives an error report for the whole code. An interpreter translates and executes the code line by line and stops when it finds an error. An interpreter is mostly used while developing a program; a compiler is used to translate the final program.

Compiler and interpreter Compiler whole sourcecode translates ALLof it at once executable file:run any time source code,one line translates andruns that line output; then thenext line Interpreter errors: one report listing all of them, no executable made repeat line by line; stops at the first error
Fig. 1: a compiler translates the whole program into an executable file; an interpreter translates and runs one line at a time
Lesson sequence

Forty-five minutes, phase by phase

TimePhaseWhat happens in the roomGrouping
0 to 5 minHook: predictOpen with the question in the title, All at once, or line by line.. Every program has to become machine code before the processor can run it. Put the figure on the board: it is the one picture every idea in the lesson returns to.Whole class, then pairs
5 to 13 minTeach and check: Three translatorsWhich translator you need depends on the language the source code is written in.Whole class, then pairs
13 to 21 minTeach and check: How errors are reportedHere is a short program with mistakes on lines 2 and 4. Model the worked example Compiler on the board, one line at a time.Pairs
21 to 30 minTeach and check: Compiler or interpreter?Both have strengths. Your turn: A developer is still writing and testing a game. Which translator is more useful now, and why?Think-Pair-Share
30 to 36 minCheckThe four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong.Individual, then whole class
36 to 43 minPlenaryThe exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording.Individual, random call
43 to 45 minExit and homeworkSet the worksheet below (6 questions, 16 marks). Learners self-assess against the objectives before they leave.Individual
Timing and contingency

Protect the parts that carry the learning

The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.

Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.

Cut first if the build overruns: the last check in Compiler or interpreter?, never the check or the plenary.

In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.

Running the cooperative task

Think-Pair-Share

Pose the question, give thirty seconds of silent thinking, then a minute to compare with a partner before a few pairs share with the class. The silent minute is the part that cannot be cut.

The full structure, with its variations and the other twelve, is on the cooperative-learning page.

Examiner traps to pre-empt

What to head off, and how

Trap learners fall intoTeaching move that pre-empts it
An assembler is never used for a high-level language, and a compiler or interpreter is never used for assembly language.Match the translator to the language.
A compiler does not run the program while it is translating.It reports all the errors it can find, and only an error-free program becomes an executable file.
Worksheet

Assemblers, compilers and interpreters: worksheet

6 questions, 16 marks. Written in the style of the papers; no past paper question is reproduced.

NameClassDate
Q1 · explain[3 marks]

Describe how a compiler translates a high-level language program and how it reports errors.

Q2 · explain[3 marks]

Describe how an interpreter translates a high-level language program and how it reports errors.

Q3 · recall[2 marks]

State the type of translator needed for: (a) a program written using mnemonics such as LDD and ADD; (b) a program written in Python that is to be sold as an executable file.

Q4 · explain[4 marks]

Give two advantages of a compiler and two advantages of an interpreter.

Q5 · apply[2 marks]

A programmer uses an interpreter while writing an app and a compiler when the app is finished. Explain why.

Q6 · analysis[2 marks]

A program is run with an interpreter. It outputs two lines and then stops with an error message. When the same program is compiled, nothing is output at all. Explain the difference.

Answer key and marking notes
Q1 · 3 marks
  • It translates the whole program at once, before it is executed.
  • It produces an executable file (machine code).
  • If errors are detected it produces an error report for the whole code (and no executable).
Q2 · 3 marks
  • It translates one line of code and then executes it,
  • before moving on to the next line (line by line).
  • It stops execution when an error is found and reports that error.
Q3 · 2 marks
  • (a) Assembler.
  • (b) Compiler.
Q4 · 4 marks
  • Compiler: produces an executable file that runs without the translator / runs faster once compiled.
  • Compiler: the source code is not given to users, so it cannot easily be copied or changed.
  • Interpreter: stops at the error, so it is easy to see where the error is.
  • Interpreter: code can be tested line by line / in parts during development, without translating the whole program.
Q5 · 2 marks
  • During development an interpreter helps debugging, because it stops at each error and parts of the code can be tested as they are written.
  • When finished, a compiler produces an executable file to distribute, which runs quickly without the source code or a translator.
Q6 · 2 marks
  • The interpreter executed the lines before the error, producing output, then stopped at the error.
  • The compiler translates the whole program first; because there is an error no executable is produced, so nothing runs and only an error report is given.
Quiz

6 multiple-choice questions on this lesson

From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.

Q11 mark

How does an interpreter translate a high-level program?

  • AIt translates and executes one line at a time, stopping when it finds an error
  • BIt translates the whole program at once and produces an executable file
  • CIt converts each mnemonic into a single machine code instruction
  • DIt lists every error in the program before running any of it
Q21 mark

A program for a games console is written using mnemonics such as LDD, ADD and STO. Which translator is needed before it can run?

  • AAn assembler
  • BA compiler
  • CAn interpreter
  • DA bootloader
Q31 mark

Line 04 of this program is missing a closing quotation mark. The program is run using an interpreter.

01  Score ← 5
02  OUTPUT Score
03  OUTPUT Score * 2
04  OUTPUT "Done
05  OUTPUT Score + 1
What happens?

  • A5 and 10 are output, then the interpreter stops and reports the error in line 04
  • BNothing is output, and an error report for the whole program is shown
  • C5, 10 and 6 are output, and line 04 is skipped
  • DAn error is reported at line 01, before anything is output
Q41 mark

What does a compiler produce when it translates a program that has no errors?

  • AAn executable file
  • BAn error report for each line
  • CA list of mnemonics
  • DA device driver
Q51 mark

The same program is compiled instead of interpreted.

01  Score ← 5
02  OUTPUT Score
03  OUTPUT Score * 2
04  OUTPUT "Done
05  OUTPUT Score + 1
What happens?

  • ANo executable file is produced, nothing is output and the error in line 04 is reported
  • B5 and 10 are output, then the compiler stops at line 04
  • CThe compiler fixes line 04 automatically and then outputs 5, 10, Done and 6
  • DAn executable file is produced and the error only appears when it is run
Q61 mark

A company has finished writing a game. It wants customers to run it quickly without being able to see or change the source code. Which translator should it use for the final version, and why?

  • AA compiler, because customers receive only the executable file, which runs without translation
  • BAn interpreter, because it stops at errors so customers can fix them
  • CA compiler, because it translates and runs the code one line at a time
  • DAn interpreter, because it creates an executable that hides the source code
Quiz key
Q1: A

An interpreter translates one line, executes it, then moves on, and stops at the first error it meets. Translating everything at once into an executable and listing all errors in one report describe a compiler. Converting mnemonics into machine code is what an assembler does.

Q2: A

Mnemonics are assembly language, which is translated into machine code by an assembler. Compilers and interpreters translate high-level languages, never assembly language. A bootloader is firmware that loads the OS; it is not a translator.

Q3: A

The interpreter translates and runs lines 01 to 03, so 5 and then 10 are output. At line 04 it finds the error, stops and reports it, so line 05 is never reached. Producing no output and one report for the whole code is how a compiler behaves. An interpreter does not skip errors, and lines 01 to 03 contain no error.

Q4: A

A compiler translates the whole program into machine code saved as an executable file, which can be run again and again without translating. An error report is only produced when errors are found. Mnemonics belong to assembly language, and device drivers are a type of system software.

Q5: A

A compiler checks the whole program before running any of it. Because line 04 contains an error, it gives an error report and produces no executable, so nothing is output at all. Outputting 5 and 10 first is interpreter behaviour. Compilers do not fix errors themselves, and an executable is only created from error-free code.

Q6: A

A compiler produces an executable file: it runs quickly because no translation is needed each time, and customers never receive the source code. An interpreter would need the source code and the interpreter on each customer's machine, and its stopping at errors helps developers, not customers. Line-by-line execution describes an interpreter, and interpreters do not produce executables.

Slides

Slides for this lesson

A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.

Also for this topic

Everything else you can use

Original work by the TheLucidSTEM team. The worksheet items are written in the style of the papers; no past paper question is reproduced.
Previous lessonHigh-level and low-level languages