Why translators are needed

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Why translators are needed

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which statement is correct about what a CPU can run directly?
A The CPU can only run machine code
B The CPU can run Python source code directly
2. What is the job of a translator?
A Convert machine code into a faster CPU
B Convert source code into machine code
3. Which list contains only types of translator?
A Assembler, compiler, interpreter
B Assembler, compiler, spreadsheet
4. Which translator is used for assembly language?
A Assembler
B Interpreter
5. A program is written in a high-level language. Which translators could be used?
A Only an assembler
B A compiler or an interpreter

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1translator AThe only language the CPU can run directly, made up of binary instructions
2machine code BSoftware that converts a program written in a high-level or assembly language into machine code the CPU can run
3An assembler translates assembly language into machine code Chigh-level code -> compiler or interpreter -> machine code
4A compiler or interpreter translates a high-level language into machine code DThe CPU can only run machine code. High-level source code such as Python must be translated into machine code first.
5The CPU runs Python source code directly, so no translator is needed Eassembly language -> assembler -> machine code
6high-level code -> assembler -> machine code FAn assembler only translates assembly language. High-level code needs a compiler or an interpreter.

Definitions

translator

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
source code -> __________ -> machine code
2.
assembly code -> _________ -> machine code
3.
The CPU can only run _______ code
4.
Types: assembler, ________, interpreter
5.
input: source code output: ____________

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A language ← 'Python'
B translator ← 'assembler'
C output ← 'machine code'
D OUTPUT translator
Question 2
A translator ← 'compiler'
B language ← 'assembly'
C output ← 'machine code'
Question 3
A source ← 'high-level code'
B translator ← 'compiler'
C output ← translate(source)
D cpu_runs ← 'source code'
Question 4
A REPEAT
B machine ← translate(line)
C CPU.run(line)
D UNTIL no more lines
Question 5
A source ← 'game.c'
B translator ← 'compiler'
C source ← translator(machine)
D SAVE machine AS 'game.exe'

Answer Key

Why translators are needed
Section A: Quick Questions
Q1
A — The CPU can only run machine code
Q2
B — Convert source code into machine code
Q3
A — Assembler, compiler, interpreter
Q4
A — Assembler
Q5
B — A compiler or an interpreter
Section B: Match the Pairs
Q1
translator → Software that converts a program written in a high-level or assembly language into machine code the CPU can run
Q2
machine code → The only language the CPU can run directly, made up of binary instructions
Q3
An assembler translates assembly language into machine code → assembly language -> assembler -> machine code
Q4
A compiler or interpreter translates a high-level language into machine code → high-level code -> compiler or interpreter -> machine code
Q5
The CPU runs Python source code directly, so no translator is needed → The CPU can only run machine code. High-level source code such as Python must be translated into machine code first.
Q6
high-level code -> assembler -> machine code → An assembler only translates assembly language. High-level code needs a compiler or an interpreter.
Section C: Definitions
Q1
translator — Software that converts high-level or assembly code into machine code, because the CPU can only run machine code. Types: assembler, compiler, interpreter.
Section D: Fill in the Blanks
Q1
source code -> translator -> machine code
Q2
assembly code -> assembler -> machine code
Q3
The CPU can only run machine code
Q4
Types: assembler, compiler, interpreter
Q5
input: source code output: machine code
Section E: Spot the Error
Q1
B — Python is a high-level language, so it is translated by a compiler or an interpreter. An assembler only translates assembly language. The line should be translator ← 'interpreter'.
Q2
A — Assembly language is translated into machine code by an assembler, not a compiler. The line should be translator ← 'assembler'.
Q3
D — The CPU can only run machine code, so it cannot run source code directly. The line should be cpu_runs ← 'machine code'.
Q4
C — The line of source code must be translated first, and the CPU runs the machine code produced. It should be CPU.run(machine), not CPU.run(line).
Q5
C — A translator takes source code as input and gives machine code as output. The line has them the wrong way round. It should be machine ← translator(source).