Learning Objectives
By the end of this lesson, you will be able to:
- Explain what is meant by ahigh-level languageand alow-level language, including the advantages and disadvantages of each
- Understand thatassembly languageis a form of low-level language that usesmnemonics, and that anassembleris needed to translate assembly language into machine code
- Describe the operation, advantages and disadvantages of acompilerand aninterpreter
- Explain the role of anIDEin writing program code and the common functions IDEs provide
Key Terms
Programming Language
A set of rules that provides a way of telling the computer what operation to perform.
High-Level Language (HLL)
A programming language that uses English-like statements, is machine-independent and easy to read/write.
Low-Level Language (LLL)
A programming language that deals directly with hardware or corresponds to a specific machine. Machine-dependent.
Machine Code
First-generation language. Binary representation of instructions directly executable by the processor (0s and 1s).
Assembly Language
Second-generation language. Uses mnemonics (e.g. LDA, STA, ADD) instead of binary.
Mnemonic
A short-code word (e.g. LDA = Load, STA = Store) used in assembly language to represent an instruction.
Source Code
A program written in assembly language or a high-level language (not machine code).
Object Code
A program written in machine language (binary) — the output of a translator.
Translator
A utility program that translates source code into machine code (object code).
Compiler
A translator that converts an entire high-level program into machine code in one go, producing an executable file.
Interpreter
A translator that translates and executes high-level code one line at a time. Stops when an error is found.
Assembler
A translator that converts assembly language into machine code (one-to-one relationship).
Integrated Development Environment (IDE)
A software application that provides comprehensive facilities to programmers for software development.
Debugger
A tool that allows the programmer to step through code line-by-line or set breakpoints to find logic errors.
Prettyprinting
Automatic colour-coding and indentation of code to make it easier to read.
Breakpoint
A marker that stops program execution at a certain point so the programmer can inspect variable values.
Auto-completion
A code editor feature that offers context-sensitive prompts for variable names and reserved words.
Error Diagnostics
Tools that identify, understand and help fix errors in code — includes highlighting and error messages.
1. High-Level vs Low-Level Languages
Aprogramming languageacts as a bridge between what humans understand and what a computer understands. Early computers were complex and instructions had to be written in binary code (0s and 1s). Over time, new generations of programming languages have enabled people to become faster and more efficient at writing programs.
Low-Level Languages
Allow direct control over hardware components such as memory and registers. Written for specific processors to ensure they embed the correct machine architecture.
- First generation:Machine code — written in binary, directly executable by the processor.
- Second generation:Assembly code — written using mnemonics (e.g. LDA, STA, INP). One assembly instruction translates to one machine code instruction.
- Needs anassemblerto translate into machine code.
- Hardware knowledge is a prerequisite for writing programs.
- Little to no abstraction.
- Machine-dependent — code only works with one specific type of processor.
High-Level Languages
Use English-like statements to allow users to program with easy-to-use code. High-level languages allow for clear debugging and once programs are created they are easier to maintain.
- Written in languages like Python, Java, C++, Visual Basic.
- One source code instruction translates intomanymachine code instructions.
- Needs acompilerorinterpreterto translate into machine code.
- Independent of the type of computer being used (portable).
- Easier to read, write, debug and maintain.
- Quicker to write programs.
- High level of abstraction — little hardware knowledge required.
Advantages and Disadvantages
| Language | Advantages | Disadvantages |
|---|---|---|
| High-Level |
|
|
| Low-Level |
|
|
Exam Tip
When describing low-level languages, don't just say "they are faster." You must say theyallow direct control over hardware or memory, which leads to greater efficiency. Be specific to earn the mark.
Activity 1: Language Types
Complete the table to identify whether each example of computer code is High-level, Assembly language or Machine code.
| Computer code | High-level | Assembly | Machine code |
|---|---|---|---|
| 101101110011011011100110 | |||
| LDA X / INC X / STA Y | |||
| FOR x ← 1 TO 10 / READ n / ENDFOR |
Solution:
- 101101110011011011100110→Machine code— binary only (0s and 1s).
- LDA X / INC X / STA Y→Assembly language— uses mnemonics (LDA, INC, STA).
- FOR x ← 1 TO 10 / READ n / ENDFOR→High-level language— uses English-like keywords (FOR, READ, ENDFOR).
Check Your Understanding: Languages
1. What is a high-level language? [2 marks]
- [1]A programming language that uses English-like statements
- [1]It is machine-independent / requires no knowledge of hardware
2. Give two advantages of a high-level language. [2 marks]
- [1]Easier to read, write and understand programs
- [1]Easier to debug and maintain / portable / quicker to write programs
3. Give two advantages of a low-level language. [2 marks]
- [1]Can make use of special hardware / machine-dependent instructions
- [1]Can write code that doesn't take up much space / performs a task very quickly
4. What generation is machine code and what generation is assembly language? [2 marks]
- [1]Machine code is first generation
- [1]Assembly language is second generation
5. Why do programmers not prefer to write code in machine language? [2 marks]
- [1]Difficult to understand / hard to modify or find errors
- [1]All memory addresses have to be remembered / complicated to manage data manipulation and storage
6. What is meant by source code and object code? [2 marks]
- [1]Source code — program written in assembly language or high-level language
- [1]Object code — program written in machine language (binary)
2. Assembly Language
Assembly languageis a second-generation, low-level language designed to simplify the writing of machine code instructions for programmers. It usesmnemonics— short-code words that are easier to remember than binary.
Why Programmers Use Assembly
- Need to make use of specific hardware or parts of the hardware
- To complete specific machine-dependent instructions
- To ensure that too much space is not taken up in RAM
- To ensure code can be completed much faster
- Used for embedded systems and device drivers where it is necessary to instruct hardware directly
- LDA— Load value into the accumulator
- ADD— Add value to the accumulator
- STO— Store value in RAM
- INP— Input a value
- STA— Store in a specific location
- OUT— Output a value
- DAT— Data declaration
How the Assembler Works
- Amnemonicis received by the computer and looked up within a specific table.
- Anassembleris needed to check the word so it can be converted into machine code.
- If a match from the word is found (e.g. STO), the word is replaced with the relevant binary code.
- One assembly instruction translates toonemachine code instruction (one-to-one relationship).
- Code only works with one specific type of processor.
| Advantages of Assembly Language | Disadvantages of Assembly Language |
|---|---|
|
|
Example: Assembly Code to Machine Code
Activity 2: Assembly Language
- Look at the two pieces of code below. Identify which is high-level and which is low-level. [2]Program ABEGINVAR First, Second: INTEGERREAD First, SecondFirst := First + SecondWRITE FirstENDProgram BINPSTA FIRSTINPSTA SECONDLDA FIRSTADD SECONDSTA FIRSTOUTFIRST DATSECOND DAT
- Explain two reasons why a programmer might choose to write in assembly language. [2]
Solution:
- Program A ishigh-level language(uses BEGIN, VAR, READ, WRITE). Program B islow-level assembly language(uses INP, STA, LDA, ADD, OUT mnemonics).
- Any two from: to make use of special hardware [1]; to use specific machine-dependent instructions [1]; to write code that doesn't take up much space in primary memory [1]; to write code that performs a task very quickly [1].
Check Your Understanding: Assembly
1. What is a mnemonic? Give an example. [2 marks]
- [1]A short-code word used in assembly language to represent an instruction
- [1]Example: LDA (Load), STA (Store), ADD
2. What is an assembler? [2 marks]
- [1]A translator that converts assembly language into machine code
- [1]It looks up each mnemonic in a table and replaces it with the relevant binary code
3. Why is assembly language described as a low-level language? [2 marks]
- [1]It deals directly with hardware / is machine-dependent
- [1]Programmer works with memory directly / it translates one-to-one to machine code
4. Explain one disadvantage of using assembly language compared to a high-level language. [1 mark]
- [1]It takes a longer time to write and debug programs / it is machine-dependent / harder to understand
5. How many machine code instructions does one assembly instruction usually translate into? [1 mark]
- [1]One (one-to-one relationship)
6. Why is assembly language used for embedded systems and device drivers? [2 marks]
- [1]It allows direct control over hardware
- [1]It is memory-efficient / fast execution where resources are limited
3. Translators: Compilers, Interpreters & Assemblers
A computer can only understand machine language. Programs written in assembly language and high-level language must be translated into machine language before they can be executed.Translatorsare utility programs that translate source code into object code (machine language).
Compiler
- Translates anentirehigh-level language program into machine code in one go.
- Produces anexecutable filethat runs directly on the computer.
- If errors are found, an error report is produced instead of a compiled program.
- Compiled code can be distributed and run without the compiler.
- No need for translation at run-time.
- Speed of execution is faster; code is usually optimised.
- Original source code is kept secret.
- Used when a program isfinishedand has been checked for syntax errors.
Interpreter
- Translates and executes codeone line at a time.
- Each line is executed after translation.
- Stops executing when an error is found.
- No executable file is produced.
- Code does not need to be recompiled when it is changed.
- Easier to debug — stops at the first error.
- Slower execution; every time the program is run it has to be translated.
- Mainly used whendevelopinga program.
Assembler
- Translatesassembly languageinto machine code.
- Takes basic commands and operations and converts them into binary code.
- The translation process is typically aone-to-oneprocess.
- Produces an executable file that can be used without the assembler.
- Memory-efficient; speed of execution is faster.
- Hardware-oriented — requires fewer instructions.
- Machine-dependent — works with one specific processor.
Compiler vs Interpreter vs Assembler — Comparison Table
This is a very important exam topic. Learn the differences between the three types of translator.
| Feature | Compiler Translates HLL | Interpreter Translates HLL | Assembler Translates LLL |
|---|---|---|---|
| What does it translate? | High-Level → Machine | High-Level → Machine | Assembly → Machine |
| How does it translate? | Whole Program | Line by Line | One-to-One |
| Output (executable file?) | Yes | No | Yes |
| Speed of execution | Fast | Slow | Fast |
| Memory usage | More | Less | Less |
| Debugging | Harder | Easier | Easier |
| Recompilation needed? | Yes | No | Yes |
| Typical use | Final Program | Development | Embedded Systems |
| Key advantage | |||
| Key disadvantage |
Quick Memory Aid
- Compiler—Compiles thewholeprogram at once, produces anexecutable.
- Interpreter—Interprets and executesline by line, stops at the first error.
- Assembler— Translatesassemblyinto machine code,one-to-onerelationship.
Activity 3: Translators
- Describe the difference between a compiler and an interpreter. [2]
- Give one advantage and one disadvantage of using a compiler. [2]
- Give one advantage and one disadvantage of using an interpreter. [2]
- Describe the difference between a compiler and an assembler. [2]
- Pedro has written a program in a high-level language. His friend needs to use it immediately. Pedro does not know what software is available on the laptop and the internet connection is slow. Which translator should Pedro use? Explain. [3]
Solution:
- Compiler translates the whole program in one go [1]; interpreter translates one line at a time [1].
- Advantage:Faster execution / produces an executable / no need for translation at run-time [1].Disadvantage:Code must be recompiled when changed / harder to debug / memory intensive [1].
- Advantage:Easier to debug / code doesn't need recompiling when changed [1].Disadvantage:Slower execution / translation software needed at run-time [1].
- Compiler translates high-level language into machine code [1]; assembler translates assembly language into machine code [1].
- Pedro should use acompiler[1]. The friend may not have an interpreter installed on their laptop [1]. Compiling produces an executable file that can be distributed and run without translation software [1].
Check Your Understanding: Translators
1. What is a translator? [2 marks]
- [1]A program that translates source code into machine code
- [1]So it can be executed directly by a processor
2. What is a compiler? [2 marks]
- [1]Translates high-level language into machine code all in one go
- [1]Produces an executable file
3. What is an interpreter? [2 marks]
- [1]Translates and executes code line by line
- [1]Stops executing when an error is found
4. What is an assembler and what does it translate? [2 marks]
- [1]A translator that converts assembly language into machine code
- [1]Uses a table to look up mnemonics and replaces them with binary
5. Why does a computer need to translate high-level code before it is executed? [1 mark]
- [1]The processor can only understand machine code (binary)
6. Which translator is usually used during program development and why? [2 marks]
- [1]An interpreter
- [1]It stops at the first error, making debugging easier
4. Integrated Development Environments (IDEs)
AnIntegrated Development Environment (IDE)is a software application that provides comprehensive facilities to computer programmers for software development. It makes writing high-level languages more efficient.
Code Editor
Allows a program to be written and edited without using a separate text editor.
Translator
Built-in compiler or interpreter to enable the program to be executed.
Debugger
Step through code line by line or set breakpoints to find logic errors.
Error Diagnostics
Dynamic error checking, alerts the programmer and suggests corrections.
Auto-completion
Context-sensitive prompts with text completion for variable names and reserved words.
Prettyprinting
Automatic colour-coding of keywords, comments, strings and auto-indentation.
Key IDE Features
1. Code Editor
Allows a program to be written and edited without the need to use a separate text editor. This speeds up the program development process.
- Basic code formatting tools — changing font, size, making text bold
- Prettyprint — using colour to identify keywords
- Code editing — auto-completion and auto-correction, bracket matching, syntax checks
- Commenting code — allows sections to be commented out easily
2. Translator
Most IDEs provide a translator — this can be a compiler and/or an interpreter. The interpreter is often used for developing the program and the compiler to produce the final version.
3. Runtime Environment with a Debugger
A debugger runs the program under development and allows the programmer to:
- Step throughthe program a line at a time (single stepping)
- Set abreakpointto stop execution at a certain point
- A report window shows the contents of variables and expressions at that point
- Allows the programmer to find logic errors and check the program works as intended
4. Error Diagnostics and Auto-correction
Dynamic error checking finds possible errors as the program code is being typed, alerts the programmer at the time and provides a suggested correction. Many errors can be found and corrected before the program is run.
5. Auto-completion
Code editors can offer context-sensitive prompts with text completion for variable names and reserved words.
6. Auto-documenter and Prettyprinting
IDEs can provide an auto-documenter to explain the function and purpose of code. Most code editors colour-code the words and lay out the program in a meaningful way — this is called prettyprinting.
Example: Prettyprinting in Python IDLE
Keywords (def, for, in) are colour-coded, strings are shown in a different colour, and indentation is automatic.
Activity 4: IDEs
- Explain what is meant by the term IDE. [2]
- Describe the following IDE features and give a suitable example for each:
- Auto-completion
- Auto-correction
- Prettyprinting
- Identify two other features that should be included in an IDE and give a reason why each is necessary. [4]
Solution:
- An Integrated Development Environment is a software application that provides comprehensive facilities to programmers for software development [1]. It includes tools such as a code editor, translator and debugger [1].
- Auto-completion [2]:Offers context-sensitive prompts with text completion for variable names and reserved words [1]. Example: typing "pri" suggests "print" in Python [1].Auto-correction [2]:Finds possible errors as code is typed, alerts the programmer and provides a suggested correction [1]. Example: highlighting a missing bracket in red [1].Prettyprinting [2]:Automatic colour-coding and indentation of code to make it easier to read [1]. Example: keywords shown in a different colour in the editor [1].
- Any two from:Debugger [2]— allows stepping through code and setting breakpoints to find logic errors;Translator [2]— compiles or interprets code without needing extra software;Runtime environment [2]— allows the program to be run and output viewed;Error diagnostics [2]— identifies and helps fix errors.
Check Your Understanding: IDEs
1. What is an IDE? [2 marks]
- [1]An Integrated Development Environment is a software application that provides comprehensive facilities for software development
- [1]It includes a code editor, translator, debugger and other tools
2. What is a debugger? [2 marks]
- [1]A program that runs the program under development
- [1]Allows stepping through line by line or setting breakpoints to find logic errors
3. What is a breakpoint? [1 mark]
- [1]A marker that stops the execution of a program at a certain point so the programmer can inspect variable values
4. What is prettyprinting? [2 marks]
- [1]Automatic colour-coding of keywords, comments and strings
- [1]Automatic indentation of code to make it easier to read
5. Give two benefits of using an IDE for a programmer. [2 marks]
- [1]Tools are all in one place / no need for separate software
- [1]Debugger and error diagnostics make it easier to find and fix errors
6. What is the difference between the interpreter and compiler features within an IDE? [2 marks]
- [1]The interpreter is often used during development for testing/debugging
- [1]The compiler is used to produce the final version of the program for distribution
Key Takeaways
- High-level languagesuse English-like statements, are machine-independent and easier to read/write/debug.
- Low-level languagesdeal directly with hardware, are machine-dependent and are more memory-efficient but harder to write.
- Machine codeis first-generation, binary, and directly executable by the processor.
- Assembly languageis second-generation and usesmnemonics(e.g. LDA, STA, INP).
- Anassemblertranslates assembly language into machine code (one-to-one relationship).
- Acompilertranslates the whole high-level program at once and produces an executable file.
- Aninterpretertranslates and executes code line by line, stopping at the first error.
- Compilers givefaster executionbut are harder to debug; interpreters areeasier to debugbut slower to execute.
- AnIDEprovides a code editor, translator, debugger, error diagnostics, auto-completion and prettyprinting.
- Adebuggerallows stepping through code line by line and setting breakpoints to find logic errors.
- Prettyprintingautomatically colour-codes keywords and indents code to make it easier to read.
Question Bank
1. Give two benefits of writing a program in a high-level language. [2 marks]
- [1]Easier to read, write and understand programs / quicker to write programs
- [1]Easier to debug and maintain / machine-independent (portable)
2. Give two benefits of writing a program in a low-level language. [2 marks]
- [1]Can make use of special hardware / machine-dependent instructions
- [1]Code doesn't take up much space / performs a task very quickly
3. State why a compiler or an interpreter is needed when running a high-level program on a computer. [1 mark]
- [1]The computer/processor can only understand machine code (binary)
4. Describe the differences between a compiler and an interpreter. [4 marks]
- [1]Compiler translates the whole code in one go / interpreter translates one line at a time
- [1]Compiler creates an executable file / interpreter does not
- [1]Compiler reports errors at the end / interpreter stops when it finds an error
- [1]Compiled code runs faster / interpreted code runs slower
5. Describe the differences between a compiler and an assembler. [2 marks]
- [1]Compiler translates high-level language into machine code
- [1]Assembler translates assembly language (low-level) into machine code
6. Explain why a programmer might choose to write a program in assembly language. [2 marks]
- [1]To make use of special hardware / machine-dependent instructions
- [1]To write code that doesn't take up much space / performs a task very quickly
7. Five statements about interpreters and compilers are shown. Tick to show whether each statement refers to an interpreter or a compiler. [5 marks]
- Creates an executable file →Compiler
- More likely to crash the computer since machine code runs directly →Compiler
- Easier to debug since each line is analysed before being executed →Interpreter
- Slow speed of execution of program loops →Interpreter
- More difficult to modify the executable code →Compiler
8. Complete the following by writing either compiler, interpreter or assembler in the spaces provided. [3 marks]
- Compilertranslates source code into object code.
- Assemblertranslates low-level language into machine code.
- Interpreterstops execution of a program as soon as it encounters an error.
9. Look at the two pieces of code. Identify which is high-level and which is low-level. [2 marks]
Program A(BEGIN / VAR / READ / WRITE / END) →High-level language[1]
Program B(INP / STA / LDA / ADD / OUT / DAT) →Low-level assembly language[1]
10. Explain what is meant by an IDE and describe two features it provides. [4 marks]
- [1]An Integrated Development Environment is a software application that provides comprehensive facilities for software development
- [1]Includes a code editor, translator, debugger and other tools
- [1]Feature 1 — e.g. debugger allows stepping through code line by line / setting breakpoints
- [1]Feature 2 — e.g. auto-completion offers prompts for variable names / prettyprinting colour-codes code
11. Use the words below to complete the sentences: Assembler, Compiler, Interpreter. [3 marks]
- To translate a program written in a high-level language, you can use acompileror aninterpreter.
- To translate a program written in a low-level language, you must use anassembler.
12. Look at the two pieces of code. Which program is easier to understand and why? [2 marks]
- [1]Program A (high-level) is easier to understand
- [1]It uses English-like statements (BEGIN, READ, WRITE) rather than mnemonics like INP, STA, LDA
13. Explain which type of translator Pedro should use for his program. His friend needs it immediately on their laptop, Pedro does not know what software is available, and the internet connection is very slow. [3 marks]
- [1]Pedro should use acompiler
- [1]A compiler produces an executable file that can be distributed and run on the friend's laptop without translation software
- [1]An interpreter would require the friend to have interpretation software installed / and would need to be run every time
14. Tick the appropriate column to indicate whether each statement about translators is True or False. [7 marks]
- An assembler translates a high-level language program →False
- It is more difficult to write a program in a low-level language →True
- Java is an assembly language →False
- It is quicker to develop a program using a high-level language →True
- You always need a compiler to run a compiled program →False
- A program that is interpreted takes a longer time to run than a compiled program →True
- Low-level languages are machine dependent →True
15. Five statements about interpreters and compilers are shown. Tick to show whether the statement refers to an interpreter or a compiler. [5 marks]
- Takes one statement at a time and executes it →Interpreter
- Generates an error report at the end of translation of the whole program →Compiler
- Stops the translation process as soon as the first error is encountered →Interpreter
- Slow speed of execution of program loops →Interpreter
- Translates the entire program in one go →Compiler