PL

4.2 Programming Languages, Translators & IDEs

Understanding high-level and low-level languages, assembly language, translators (compilers, interpreters, assemblers) and Integrated Development Environments (IDEs).

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.

High-Level Language
Assembly Language
Machine Language
Hardware

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

LanguageAdvantagesDisadvantages
High-Level
  • Independent of the type of computer being used
  • Easier to read, write and understand programs
  • Quicker to write programs
  • Programs are easier and quicker to debug
  • Easier to maintain programs in use
  • Portable — can be used on different computers
  • Programs can be larger
  • Programs can take longer to execute
  • Programs may not be able to make use of special hardware
  • Needs to be translated to machine code before running
Low-Level
  • Can make use of special hardware
  • Includes special machine-dependent instructions
  • Can write code that doesn't take up much space in primary memory
  • Can write code that performs a task very quickly
  • Memory-efficient; faster execution
  • Takes a longer time to write and debug programs
  • Programs are more difficult to understand
  • Machine-dependent — lack of portability
  • Difficult to remember syntax
  • More prone to errors

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 codeHigh-levelAssemblyMachine code
101101110011011011100110
LDA X / INC X / STA Y
FOR x ← 1 TO 10 / READ n / ENDFOR
Solution:
  • 101101110011011011100110Machine code— binary only (0s and 1s).
  • LDA X / INC X / STA YAssembly language— uses mnemonics (LDA, INC, STA).
  • FOR x ← 1 TO 10 / READ n / ENDFORHigh-level language— uses English-like keywords (FOR, READ, ENDFOR).

Check Your Understanding: Languages

  • [1]A programming language that uses English-like statements
  • [1]It is machine-independent / requires no knowledge of hardware
  • [1]Easier to read, write and understand programs
  • [1]Easier to debug and maintain / portable / quicker to write programs
  • [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
  • [1]Machine code is first generation
  • [1]Assembly language is second generation
  • [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
  • [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
Common Mnemonics
  • 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.
Assembly program to add two numbers:
LDA First   // load value of First into accumulator
ADD Second// add value of Second to accumulator
STO Sum    // store accumulator value in Sum
Advantages of Assembly LanguageDisadvantages of Assembly Language
  • Easier to understand and use compared to machine language
  • Easier to locate and correct errors
  • Can make use of special hardware
  • Memory-efficient / fast execution
  • Machine-dependent — no portability
  • Programmer needs to know a lot of detail about the internal structure of the CPU
  • Takes longer to write and debug than high-level languages

Example: Assembly Code to Machine Code

Assembly Code
INP
STA Num1
INP
ADD Num1
OUT
Num1 DAT
Machine Code (Binary)
10010101
00100011
10010101
00001100
00100110
00011001

Activity 2: Assembly Language

  1. Look at the two pieces of code below. Identify which is high-level and which is low-level. [2]
    Program A
    BEGIN
    VAR First, Second: INTEGER
    READ First, Second
    First := First + Second
    WRITE First
    END
    Program B
    INP
    STA FIRST
    INP
    STA SECOND
    LDA FIRST
    ADD SECOND
    STA FIRST
    OUT
    FIRST DAT
    SECOND DAT
  2. Explain two reasons why a programmer might choose to write in assembly language. [2]
Solution:
  1. Program A ishigh-level language(uses BEGIN, VAR, READ, WRITE). Program B islow-level assembly language(uses INP, STA, LDA, ADD, OUT mnemonics).
  2. 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]A short-code word used in assembly language to represent an instruction
  • [1]Example: LDA (Load), STA (Store), ADD
  • [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
  • [1]It deals directly with hardware / is machine-dependent
  • [1]Programmer works with memory directly / it translates one-to-one to machine code
  • [1]It takes a longer time to write and debug programs / it is machine-dependent / harder to understand
  • [1]One (one-to-one relationship)
  • [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.

FeatureCompiler
Translates HLL
Interpreter
Translates HLL
Assembler
Translates LLL
What does it translate?High-Level → Machine
  • Translates source code fromhigh-level languagesinto object code and then machine code
  • Code is processed by the CPU after translation
  • High-Level → Machine
  • Translates source code fromhigh-level languagesinto machine code
  • Ready to be processed by the CPU
  • Assembly → Machine
  • Translates source code fromassembly languageinto machine code
  • Takes basic commands and operations and converts them into binary code
  • How does it translate?Whole Program
  • Translates thewhole programinto machine code before it is run
  • Scans the entire program and translates it at once
  • Line by Line
  • Translates and executes codeone line at a time
  • Each line is translated and executed before moving to the next
  • One-to-One
  • One assembly instruction translates toonemachine code instruction
  • Uses a table to look up each mnemonic
  • Output (executable file?)Yes
  • Produces anexecutable fileof machine code
  • Can be distributed and run without the compiler
  • No
  • No executable fileis produced
  • Cannot be run without the interpreter
  • Yes
  • Produces anexecutable fileof machine code
  • Used without the assembler after translation
  • Speed of executionFast
  • Speed of execution isfaster
  • No translation at run-time
  • Slow
  • Speed of execution isslower
  • Slower execution of program loops
  • Fast
  • Speed of execution isfaster
  • Requires fewer instructions
  • Memory usageMore
  • Generates an intermediaryobject code
  • Needs further linking; more memory is needed
  • Less
  • Doesnotgenerate intermediary code
  • Highly efficient in terms of memory
  • Less
  • Memory-efficient
  • Writes code that doesn't take up much space in primary memory
  • DebuggingHarder
  • Generates error messages only after scanning the complete program
  • Debugging is relativelyharder
  • Easier
  • Stops working as soon as an error is spotted
  • Debugging iseasier
  • Easier
  • Easier to locate and correct errors than machine code
  • Still harder than high-level languages
  • Recompilation needed?Yes
  • Code needs to berecompiledwhen it is changed
  • Source code is required for changes
  • No
  • Code doesnotneed to be recompiled when changed
  • Every time the program is run it has to be translated
  • Yes
  • Code needs to be reassembled when changed
  • Source code is required for changes
  • Typical useFinal Program
  • Used to translate afinal program
  • For distribution of finished software
  • Examples: C, C++
  • Development
  • Used whendevelopinga program
  • For testing and debugging
  • Examples: Python, Ruby
  • Embedded Systems
  • Used forembedded systemsand device drivers
  • Where direct hardware control is needed
  • Example: Intel x86 assembly
  • Key advantage
  • Faster execution, code is optimised, source code kept secret
  • Easier to debug, code doesn't need recompiling
  • Memory-efficient, faster execution, hardware-oriented
  • Key disadvantage
  • Code must be recompiled when changed; harder to debug
  • Slower execution; translation software needed at run-time
  • Machine-dependent; difficult to write and understand
  • Quick Memory Aid

    • CompilerCompiles thewholeprogram at once, produces anexecutable.
    • InterpreterInterprets and executesline by line, stops at the first error.
    • Assembler— Translatesassemblyinto machine code,one-to-onerelationship.

    Activity 3: Translators

    1. Describe the difference between a compiler and an interpreter. [2]
    2. Give one advantage and one disadvantage of using a compiler. [2]
    3. Give one advantage and one disadvantage of using an interpreter. [2]
    4. Describe the difference between a compiler and an assembler. [2]
    5. 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:
    1. Compiler translates the whole program in one go [1]; interpreter translates one line at a time [1].
    2. 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].
    3. Advantage:Easier to debug / code doesn't need recompiling when changed [1].Disadvantage:Slower execution / translation software needed at run-time [1].
    4. Compiler translates high-level language into machine code [1]; assembler translates assembly language into machine code [1].
    5. 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]A program that translates source code into machine code
    • [1]So it can be executed directly by a processor
    • [1]Translates high-level language into machine code all in one go
    • [1]Produces an executable file
    • [1]Translates and executes code line by line
    • [1]Stops executing when an error is found
    • [1]A translator that converts assembly language into machine code
    • [1]Uses a table to look up mnemonics and replaces them with binary
    • [1]The processor can only understand machine code (binary)
    • [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

    defOutputSymbols(NumberOfSymbols, Symbol):
      forCountinrange(NumberOfSymbols):
        print(Symbol, end='')
      print()
    # ******** main program starts here ********
    OutputSymbols(5,'*')

    Keywords (def, for, in) are colour-coded, strings are shown in a different colour, and indentation is automatic.

    Activity 4: IDEs

    1. Explain what is meant by the term IDE. [2]
    2. Describe the following IDE features and give a suitable example for each:
      • Auto-completion
      • Auto-correction
      • Prettyprinting
    3. Identify two other features that should be included in an IDE and give a reason why each is necessary. [4]
    Solution:
    1. 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].
    2. 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].
    3. 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]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
    • [1]A program that runs the program under development
    • [1]Allows stepping through line by line or setting breakpoints to find logic errors
    • [1]A marker that stops the execution of a program at a certain point so the programmer can inspect variable values
    • [1]Automatic colour-coding of keywords, comments and strings
    • [1]Automatic indentation of code to make it easier to read
    • [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
    • [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]Easier to read, write and understand programs / quicker to write programs
    • [1]Easier to debug and maintain / machine-independent (portable)
    • [1]Can make use of special hardware / machine-dependent instructions
    • [1]Code doesn't take up much space / performs a task very quickly
    • [1]The computer/processor can only understand machine code (binary)
    • [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
    • [1]Compiler translates high-level language into machine code
    • [1]Assembler translates assembly language (low-level) into machine code
    • [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
    • 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
    • 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.

    Program A(BEGIN / VAR / READ / WRITE / END) →High-level language[1]

    Program B(INP / STA / LDA / ADD / OUT / DAT) →Low-level assembly language[1]

    • [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
    • 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.
    • [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
    • [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
    • 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
    • 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