

Translators. Low level vs High Level Languages
Presentation
•
Computers
•
10th Grade
•
Practice Problem
•
Easy
Ben Dobson
Used 2+ times
FREE Resource
68 Slides • 8 Questions
1
OCR GCSE
(J277)
Teacher site: craigndave.org | Student site: student.craigndave.org | Smart revise: smartrevise.co.uk
SLR 2.5 Translators. High Level and Low level languages
Characteristics of compilers and
interpreters
2
Objectives
• Describe the characteristics and purpose of different
levels of programming language, including:
• Low-level languages
• High-level languages
• Understand the purpose of translators
• Describe the characteristics of a compiler
and interpreter
3
Translators and facilities of languages
Unit 8 Logic and languages
Starter
• Name five programming languages
• Are there any major differences between each of them?
4
Translators and facilities of languages
Unit 8 Logic and languages
Starter
• High-level Programming languages
• Python, Visual Basic, C#, Java, C++, PHP, Delphi, Logo
• Query languages
• SQL
• Markup languages
• HTML, XML
• Low-level Programming languages
• Assembly language, machine code
5
Translators and facilities of languages
Unit 8 Logic and languages
Machine code
• Computers were first invented in the 1940s
6
Translators and facilities of languages
Unit 8 Logic and languages
Machine code
• In the first computers, all programs were written in
machine code
• Instructions were written in binary, so a typical
instruction looked like this:
101011001001
• Each instruction did one very small task like
LOAD the value 1 into the accumulator
• Writing programs was difficult and time-consuming
7
Translators and facilities of languages
Unit 8 Logic and languages
Details of machine code are not needed.
You will not be asked to discuss assemblers or
compare them to other translators
But…you do need to know what a low level language
is
8
9
Using Assembly Language
What will this code do?
• LOAD 2
• SUB 3
• ADD #10
• STORE 4
• HALT
10
1
2
3
4
10
25
5
10
Using Assembly Language
What will this code do?
• LOAD 2
• SUB 3
• ADD #10
• STORE 4
• HALT
11
1
2
3
4
10
25
5
•
Loads the value 25
•
Subtracts the value 5 = 20
•
Adds on 10 = 30
•
Stores the answer (30) in
memory location 4
•
Stops the program
11
Translators and facilities of languages
Unit 8 Logic and languages
Assembly language
• Assembly language allows a programmer to create
programs more easily that writing in machine code
• Each assembly language instruction maps directly to
machine code
• For example:
LDA
51
ADD
#FF
STO
52
means “Load the contents of memory location 51 into the
accumulator, add hexadecimal value FF and store the result
in location 52”
1000101100000100001001010011001
1000000000000000000000000000001
01111111110000000000000000000000
0010001001000001000010010100110
10000000000
Machine code
Assembly language
12
Translators and facilities of languages
Unit 8 Logic and languages
Assembly language
• Assembly language is processor-specific
RISC – ASSEMBLY
CISC – ASSEMBLY
13
Translators and facilities of languages
Unit 8 Logic and languages
Assembly language
• It has to be translated into machine code before it
can be executed
• As each instruction corresponds directly to a
machine code instruction, it is known as a
low-level language (along with machine code)
14
Translators and facilities of languages
Unit 8 Logic and languages
Low-level advantages
• As a programmer has direct control over how a low-level program
works they have a number
of advantages, including:
• A program written in a low-level language can run very quickly
• The code will usually require less RAM
• Statements in a low-level language can be used to control and manipulate specific
hardware components
• As such, programs such as device drivers are often written in assembly
code
15
Open Ended
What is assembly code? How many machine code instructions does it get translated into
16
Assembly code is a low level programming
language.
Each assembly instruction is translated into 1 machine code instruction
17
Translators and facilities of languages
Unit 8 Logic and languages
High-level languages
• High-level languages generally have statements that look a bit like
English or Maths
area = (base * height) / 2 print(area)
• This makes these
languages easier to
learn and understand
easy to learn
and understand
18
Translators and facilities of languages
Unit 8 Logic and languages
High-level languages
• High-level languages also have data structures such as arrays and
records
• A single statement usually translates into several machine
code instructions
• The translation is done by a program which may be either a compiler or
an interpreter
19
Open Ended
What is a high level language and what is the syntax of a high level language?How many lines of machine code is it translated into?
20
High level programming languages read more like English or maths than assembly languages.
Each line typically is translated into many machine code instructions.
21
High level programming languages read more like English or maths than assembly languages.
Each line typically is translated into many machine code instructions.
They have rules of grammar about how they are written called syntax.
22
Translators and facilities of languages
Unit 8 Logic and languages
TRANSLATORS
ASSEMBLY → MACHINE CODE (WHOLE PROGRAM)
COMPILERS → MACHINE CODE (WHOLE PROGRAM)
TRANSLATOR → MACHINE CODE (LINE BY LINE)
23
Translators and facilities of languages
Unit 8 Logic and languages
High level Languages (can be)
Machine independent
The Same C program
Different
Compiler for
RISC/CISC and/ or
UNIX/WINDOWS
32 bit vs 64 bit
24
Translators and facilities of languages
Unit 8 Logic and languages
High- and low-level languages
25
Translators and facilities of languages
Unit 8 Logic and languages
What do you think are advantages of high
level languages?
26
•There are a number of advantages of high-level languages, including:
•A high-level language is easier to learn
•Programs can be written faster in a high-level language
•It is easier to understand and debug a high-level language
•Given all these advantages, why do you think that low-level languages are still used by
some programmers?
27
Translators and facilities of languages
Unit 8 Logic and languages
Given all these advantages, why do you think that
low-level languages are still used by
some programmers?
a) Some new CPUs (e.g. for an embedded device) may
not have a compiler written for them but will have an
assembler.
b) A very skilled assembly programmer can write more
efficient code than a compiler – so small often used
blocks of code could be rewritten and called from high
level language
28
Open Ended
What do you think are the advantages of high level languages (over low level languages)?
29
Translators and facilities of languages
Unit 8 Logic and languages
High-level Advantages
• There are a number of advantages of high-level languages, including:
• A high-level language is easier to learn and debug
• Programs can be written faster in a high-level language (as fewer lines of code)
• You can use data structures e.g. lists/records
• Given all these advantages, why do you think that low-level languages
are still used by
some programmers?
30
Open Ended
Given all these advantages, why do you think that low-level languages are still used by
some programmers?
31
Translators and facilities of languages
Unit 8 Logic and languages
Given all these advantages, why do you think that
low-level languages are still used by
some programmers?
a) Some new CPUs (e.g. for an embedded device) may
not have a compiler written for them but will have an
assembler.
b) A very skilled assembly programmer can write more
efficient code than a compiler – so small often used
blocks of code could be rewritten and called from high
level language
c) Can control specific hardware components, so are useful for device drivers (to control specific hardware elements of the peripheral device)
32
33
34
35
36
Translators and facilities of languages
Unit 8 Logic and languages
Worksheet 4
• Now complete Task 1 on Worksheet 4
37
Translators and facilities of languages
Unit 8 Logic and languages
Task 1
1. Insert the following languages into the correct column in the table:
Java, VB, Assembly code, Python, C++, machine code, C#, PHP
High-level language
Low-level language
38
39
Translators and facilities of languages
Unit 8 Logic and languages
ANSWERS
40
Translators and facilities of languages
Unit 8 Logic and languages
High-level language
Low-level language
Java
Assembly code
VB
Machine code
Python
C++
C#
PHP
41
Translators and facilities of languages
Unit 8 Logic and languages
True or False?
1.
A programming language which has statements
resembling English or Maths is classified as a
high-level language
True
2.
A high-level language is closer than a low-level
language to the machine code that the computer
can execute
False
3.
Assembly code does not have to be translated into
machine code before it can be executed
False
4.
An interpreter is a program that translates a high
level language into machine code
True
5.
A compiler is a program that translates a high
level language into machine code
True
6.
There are different assembly languages for
different processor types
True
7.
There are different high-level languages for
different processor types
False
42
Translators and facilities of languages
Unit 8 Logic and languages
Disadvantages of low-level code
True or False?
1.
An assembly program written for one type of
processor will not work on a different type of
processor
True
2.
Programs written in assembly will usually execute
faster than those written in a high-level language
True
3.
Low level languages cannot control individual
components in embedded systems such as those
found in washing machines or mobile phones
False
4.
Machine code produced from assembly language
will occupy more memory than the machine code
from a high level language
False
5.
Assembly language is harder to learn than a high
level language
True
Advantage
43
Translators and facilities of languages
Unit 8 Logic and languages
Compiler
• A compiler translates a high-level language into machine
code
• The code written by the programmer is called the source code
• The code produced by the compiler is called the object code
• The object code can be saved on a secondary storage drive
and run whenever required
44
Translators and facilities of languages
Unit 8 Logic and languages
Interpreter
• An interpreter is another type of program that
translates a high-level language into machine code
• Unlike a compiler, no object code is produced
• It translates each line of code and executes
it immediately
• If it reaches a line with a syntax error, it stops
and displays an error message
45
Translators and facilities of languages
Unit 8 Logic and languages
Picture round
46
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Compilers and interpreters
Low-level language
Assembly code
Machine
code
(Binary)
Translator
(Assembler)
High-level language
Source
code
Translator
(Interpreter)
Object
code
Translator
(Compiler)
Low-level assembly code is translated into machine
code using an assembler.
Object code is machine
code – the machine code for
some libraries may be
added later.
47
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Compilers
Code will not run while a syntax
error is present.
Here, we can see an error on
line 2 that is preventing our
program from running.
48
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Compilers
The error needs correcting
before the program will run.
49
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Interpreters
This is exactly the same
program as the one we just
saw in Python – this time,
written in an early high-level
language called BBC Basic.
bbc.godbolt.org
50
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Interpreters
bbc.godbolt.org
When we run the program,
line 20 and line 30 are both
translated and run.
As you can see, it outputs
the value of counter here.
51
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Interpreters
bbc.godbolt.org
It then tries to translate line
30 – however, there is a
syntax error on line 30, so
the program fails.
52
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Interpreters
bbc.godbolt.org
Here, we can see that once
we correct the syntax error
on line 30 and run the
program again, it executes
without errors.
53
54
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Compilers and interpreters
Compiler: Translates source code from high-level languages into object code and then into machine code
ready to be processed by the CPU. The whole program is translated into machine code before it is run.
Advantages:
•No need for translation software at runtime.
•Faster to execute.
•Code is usually optimised.
•Original source code can be kept secret.
Disadvantages:
•Source code is easier to write in a high-level language, but the program will not run with syntax errors,
which can make writing the code more difficult.
•Code needs to be recompiled following any changes.
•Designed for a specific type of processor.
55
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Compilers and interpreters
Interpreter: Translates source code from high-level languages into machine code ready to be processed by
the CPU. The program is translated line by line as the program is running.
Advantages:
•Easy to write source code – the program will always run and only stop when it finds a syntax error.
•Code does not need to be recompiled following changes, making it is easier to try out commands.
•A very easy way for beginner programmers to learn how to write code.
Disadvantages:
•Translation software is required at runtime.
•Slower to execute.
•Code is not optimised.
•Source code must be available.
56
Whiteboard Compilers vs Interpreters
57
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Compilers and interpreters
Compiler: Translates source code from high-level languages into object code and then into machine code
ready to be processed by the CPU. The whole program is translated into machine code before it is run.
Advantages:
•No need for translation software at runtime.
•Faster to execute.
•Code is usually optimised.
•Original source code can be kept secret.
Disadvantages:
•Source code is easier to write in a high-level language, but the program will not run with syntax errors,
which can make writing the code more difficult.
•Code needs to be recompiled following any changes.
•Designed for a specific type of processor.
58
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Compilers and interpreters
Interpreter: Translates source code from high-level languages into machine code ready to be processed by
the CPU. The program is translated line by line as the program is running.
Advantages:
•Easy to write source code – the program will always run and only stop when it finds a syntax error.
•Code does not need to be recompiled following changes, making it is easier to try out commands.
•A very easy way for beginner programmers to learn how to write code.
Disadvantages:
•Translation software is required at runtime.
•Slower to execute.
•Code is not optimised.
•Source code must be available.
59
Translators and facilities of languages
Unit 8 Logic and languages
Compiler or interpreter?
• Some languages, such as Java, are compiled into an intermediate
stage called bytecode
• The bytecode can be interpreted on many different types of
processor using an interpreter
• Javascript, used in creating web pages, is interpreted; the source code
is included in the web page and then interpreted in the browser (e.g.
Firefox, Chrome, Internet Explorer)
60
Open Ended
What are some advantages of interpreters over compilers?
61
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Compilers and interpreters
Interpreter: Translates source code from high-level languages into machine code ready to be processed by
the CPU. The program is translated line by line as the program is running.
Advantages:
•Easy to write source code – the program will always run and only stop when it finds a syntax error.
•Code does not need to be recompiled following changes, making it is easier to try out commands.
•A very easy way for beginner programmers to learn how to write code.
Disadvantages:
•Translation software is required at runtime.
•Slower to execute.
•Code is not optimised.
•Source code must be available.
62
63
Open Ended
What the advantages of compilers over interpreters?
64
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
Compilers and interpreters
Compiler: Translates source code from high-level languages into object code and then into machine code
ready to be processed by the CPU. The whole program is translated into machine code before it is run.
Advantages:
•No need for translation software at runtime.
•Faster to execute.
•Code is usually optimised.
•Original source code can be kept secret.
Disadvantages:
•Source code is easier to write in a high-level language, but the program will not run with syntax errors,
which can make writing the code more difficult.
•Code needs to be recompiled following any changes.
•Designed for a specific type of processor.
65
Translators and facilities of languages
Unit 8 Logic and languages
Interpretor advantages
Advantages:
•Easy to write source code – the program will always run and only
stop when it finds a syntax error.
•Code does not need to be recompiled following changes, making
it is easier to try out commands – note big programs can take
hours to compile.
•Machine independence - Source code can sold – as long as
machine has its own interpreter then this can run. In compiled
languages many versions for each machine type (OS + CPU)
must be compiled and correct one installed
•A very easy way for beginner programmers to learn how to write
code.
66
Open Ended
Describe as many features of low level languages as you can
67
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
High- and low-level languages
Machine code
• Binary representation of instructions in a format that the CPU can decode
and execute.
• Includes an operation code (opcode) instruction and address or data to use
(operand).
Low-level languages
• Written in assembly language.
• Converted into machine code using a translator called an assembler.
• Used for embedded systems and device drivers where it is necessary to
instruct hardware directly.
• One instruction translates into one machine code instruction.
• Code only works with one specific type of processor.
• Programmers work with memory directly.
• Code is harder to write and understand.
• Memory-efficient.
• Code is quick to execute.
68
Open Ended
Describe as many features of high level languages as you can
69
OCR GCSE (J277)
SLR2.5 Programming languages and IDEs | Characteristics and purpose of different levels of programming language
High- and low-level languages
High-level languages
• Written in languages like Python, C++, Java and Visual Basic.
• Converted into machine code using a translator called a compiler or
interpreter.
• Makes writing programs easier by utilising commands that are like
English.
• One source code instruction translates to many machine code
instructions.
• Code will run on different types of processors.
• Programmers can use many different data structures.
• Code is quicker and easier to understand and write.
• Less memory-efficient.
• Code can be slower to execute if it is not optimised.
70
Translators and facilities of languages
Unit 8 Logic and languages
Worksheet 4
• Now complete Task 2 on Worksheet 4
71
Translators and facilities of languages
Unit 8 Logic and languages
Task 2
The Python code below contains a syntax error and a logic error.
1
# Program to perform a bubble sort
2
3
userName = ["Carl","Tamsin","Eric","Zoe","Alan","Mark"]
4
print("list of unsorted names: ", userName)
5
#numItems is the length of the list
6
7
while numItems > 1:
8
for count in range(5):
9
if userName[count] > userName[count + 1]:
10
temp = userName[count + 1]
11
userName[count] = userName[count + 1]
12
userName[count + 1] = temp
13
prnt("count = ",count, "userName[count] = ",~
userName[count], "userName[count+1] ="
,userName[count+1])
14
numItems = numItems – 1
15
prnt(userName)
(a)
There is a syntax error in line 15. What is the error?
72
Translators and facilities of languages
Unit 8 Logic and languages
(b)
Python programs are interpreted.
What, if anything will be printed when the program is run? (after corrected)
(c) If you have Python installed on your computer, try out the code and see if you are
right.
(d)If numItems = 6 is now inserted at line 6, what will happen when the program is
run?
(e)When this error is fixed, does the program give the correct result? If not,
correct it.
73
Translators and facilities of languages
Unit 8 Logic and languages
(a)
There is a syntax error in line 15. What is the error?
The print statement has been spelt incorrectly
(b)
Python programs are interpreted.
What, if anything will be printed when the program is run?
The interpreter ignores the comment on line 1, translates lines 2 and 3 and prints
the list at line 4. It then crashes on line 7 because numItems is not defined.
list of unsorted names: ['Carl', 'Tamsin', 'Eric', 'Zoe',
'Alan', 'Mark']
Traceback (most recent call last):
File "C:\W4 bubble sort, line 7, in <module>
while numItems > 1:
NameError: name 'numItems' is not defined
.
74
Translators and facilities of languages
Unit 8 Logic and languages
(c) If you have Python installed on your computer, try out the code and see if you are
right.
(d)If numItems = 6 is now inserted at line 6, what will happen when the program is
run?
The program will run to line 18, where it stops with the error message
Traceback (most recent call last):
File "C:\W4 bubble sort, line 18, in <module>
prnt (userName)
NameError: name 'prnt' is not defined
(e)When this error is fixed, does the program give the correct result? If not, correct it.
change temp = userName[count + 1] to
temp = userName[count]
See program W4 Bubble sort.py. This program was given in the lesson on Errors
and testing so most students should already have found the logic error.
75
Complete . Then ask students for each word
76
Translators and facilities of languages
Unit 8 Logic and languages
Plenary
• Complete the following by filling in the blanks
High-level languages include Python, VB and Java. They need to be
compiled or interpreted before they can be run. Assembly language is a
low-level language. It is assembled into machine code before it is run.
Compiled
Assembly language
Machine code
Python
High-level
assembled
OCR GCSE
(J277)
Teacher site: craigndave.org | Student site: student.craigndave.org | Smart revise: smartrevise.co.uk
SLR 2.5 Translators. High Level and Low level languages
Characteristics of compilers and
interpreters
Show answer
Auto Play
Slide 1 / 76
SLIDE
Similar Resources on Wayground
68 questions
IGCSE Geography-Coasts-Coastal Ecosystems
Presentation
•
9th - 10th Grade
65 questions
1.4 - Forms Of Attack
Presentation
•
9th - 10th Grade
66 questions
2 Pressure and wind
Presentation
•
10th Grade
75 questions
AP 1 Dynamics
Presentation
•
11th Grade
75 questions
Unit 2 Review
Presentation
•
9th Grade
66 questions
Summer School BIO STAAR review: Environmental Systems
Presentation
•
9th - 10th Grade
65 questions
Bonding in Physical Science
Presentation
•
9th - 10th Grade
74 questions
Fall of Rome + Byzantine Empire
Presentation
•
10th Grade
Popular Resources on Wayground
6 questions
Secondary Safety Quiz
Presentation
•
9th - 12th Grade
10 questions
MyPath Diagnostic Overview
Presentation
•
6th - 8th Grade
20 questions
Lab Safety Quiz
Quiz
•
6th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Adding and Subtracting Decimals
Quiz
•
5th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
21 questions
Lab Safety
Quiz
•
10th Grade
Discover more resources for Computers
20 questions
Early Computing
Quiz
•
7th - 12th Grade
20 questions
Module 1 Topic 1 Vocabulary
Quiz
•
9th - 12th Grade
10 questions
Exploring Computer Hardware and Software Components
Interactive video
•
6th - 10th Grade
39 questions
Safety Review
Quiz
•
9th - 12th Grade
20 questions
Digital Citizenship
Quiz
•
8th - 12th Grade
22 questions
Electronic Computing
Quiz
•
8th - 12th Grade