Machine independence

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

Machine independence

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which type of language is machine independent?
A Low-level language
B High-level language
2. Low-level code written for one type of CPU will usually run on a different type of CPU.
A True
B False
3. Why is assembly code machine dependent?
A Each CPU type has its own instruction set
B All CPUs share the same instruction set
4. A student writes one Python program and runs it on a Windows laptop and on a Mac. What does this show?
A High-level code is portable
B High-level code is machine dependent
5. How can the same high-level program run on two different types of computer?
A It is translated separately for each machine
B It is rewritten in assembly for both machines at once

Match the Pairs

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

Left columnRight column
1machine independent AA high-level program is portable, but each type of computer still needs a translator (compiler or interpreter) to turn it into its own machine code.
2machine dependent BLow-level code is machine dependent. It uses the instruction set of one CPU type, so it will not run on a different type of CPU without being rewritten.
3A high-level program is portable: the same source code can be translated separately for a PC and a phone CCode written in this kind of language can run on different types of computer, as long as each one has a translator. High-level languages are like this.
4Assembly code is machine dependent because each CPU type has its own instruction set DCode written in this kind of language only works on one type of CPU because it uses that CPU's own instruction set. Low-level languages are like this.
5"Assembly code written for one CPU will run on any computer." EMOV AX, 5 ; works on one CPU type only
6"A high-level program can run on any computer without being translated." Fprint("Hello") # same code on PC and phone

Definitions

machine independent

Fill in the Blanks

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

1.
highLevelPortable ← ____
2.
lowLevelPortable ← _____
3.
FOR i ← 1 __ numMachines TRANSLATE(program, i) NEXT i
4.
differentSets ← intelSet _ armSet
5.
IF machineDependent _ TRUE THEN OUTPUT "New code needed per CPU" ENDIF

Spot the Error

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

Question 1
A language = "Python"
B level = "low"
C portable = True
D print(portable)
Question 2
A language = "Python"
B machine_independent = False
C print(machine_independent)
Question 3
A def is_portable(level)
B return level == "high"
C print(is_portable("high"))
Question 4
A cpu_a = "x86"
B cpu_b = "ARM"
C print("Each has its own set")
D same_set = True
Question 5
A code = "assembly"
B machine_dependent = True
C if not machine_dependent:
D print("Rewrite code")

Answer Key

Machine independence
Section A: Quick Questions
Q1
B — High-level language
Q2
B — False
Q3
A — Each CPU type has its own instruction set
Q4
A — High-level code is portable
Q5
A — It is translated separately for each machine
Section B: Match the Pairs
Q1
machine independent → Code written in this kind of language can run on different types of computer, as long as each one has a translator. High-level languages are like this.
Q2
machine dependent → Code written in this kind of language only works on one type of CPU because it uses that CPU's own instruction set. Low-level languages are like this.
Q3
A high-level program is portable: the same source code can be translated separately for a PC and a phone → print("Hello") # same code on PC and phone
Q4
Assembly code is machine dependent because each CPU type has its own instruction set → MOV AX, 5 ; works on one CPU type only
Q5
"Assembly code written for one CPU will run on any computer." → Low-level code is machine dependent. It uses the instruction set of one CPU type, so it will not run on a different type of CPU without being rewritten.
Q6
"A high-level program can run on any computer without being translated." → A high-level program is portable, but each type of computer still needs a translator (compiler or interpreter) to turn it into its own machine code.
Section C: Definitions
Q1
machine independent — A language whose code can run on different types of computer. High-level languages are machine independent (portable); low-level languages are machine dependent.
Section D: Fill in the Blanks
Q1
highLevelPortable ← TRUE
Q2
lowLevelPortable ← FALSE
Q3
FOR i ← 1 TO numMachines TRANSLATE(program, i) NEXT i
Q4
differentSets ← intelSet ≠ armSet
Q5
IF machineDependent = TRUE THEN OUTPUT "New code needed per CPU" ENDIF
Section E: Spot the Error
Q1
B — Python is a high-level language, so level should be "high". High-level languages are the portable, machine independent ones.
Q2
A — Assembly is a low-level language, so it is machine dependent. Python is high-level and portable, so the language on line 1 should be "Assembly".
Q3
A — A function definition must end with a colon. The line should be def is_portable(level): so the function can run and check that high-level code is portable.
Q4
D — Each type of CPU has its own instruction set, so x86 and ARM do not share one. same_set should be False, which is why low-level code is machine dependent.
Q5
C — Machine dependent code must be rewritten for a different CPU. The condition should be if machine_dependent:, not its opposite.