Study Guide

Programming Languages and Translators

Why people write programs in high-level languages that the CPU cannot run directly: how high-level and low-level languages compare, what assembly language and an assembler are, how a compiler and an interpreter each translate and report errors, and what an IDE adds.

Lesson 3.10 Computer Systems

For: Cambridge IGCSE Computer Science learners

Stage: Think

A CPU that knows one language

A CPU can only carry out machine code: patterns of 0s and 1s from its own instruction set (Lesson 3). A school team (made up for this lesson) wants to write a computer game, with thousands of instructions.

Think it through

Would you want the team to write the whole game as 0s and 1s? Say what would be hard about it, and what you would want a programming language to be like instead.

Show what happens

A game written in binary would be extremely slow to write and nearly impossible to read or correct. People want a language of words and symbols that they can read and write, where one line can do a lot. The cost is that the CPU cannot run it as it is, so something has to translate it into machine code first.

Programming languages fall into two groups.

A high-level language is written in words and symbols close to human language, such as Python or Java, and one statement can stand for many machine-code instructions. The program is called source code until it is translated. A high-level language is independent of any one type of CPU: the same source code can be translated for different CPUs. That is called machine independence.

A low-level language is close to the instructions the CPU carries out, and so depends on the type of CPU it is written for. Machine code is the lowest level of all, and assembly language, met next, is the other low-level language.

Here is one calculation, adding the numbers held at two memory addresses of a made-up computer and keeping the result, written three ways:

Total ← First + Second       // high-level (Cambridge pseudocode)

LOAD 4                       // low-level: assembly language
ADD 5
STORE 6

0001 0100                    // low-level: machine code
0010 0101
0100 0110

One high-level line became three lower-level instructions, and the machine code is the only one of the three that the CPU can carry out without translation.

Stage: Predict

When would you choose each?

Two programs are needed. A phone game must run on both Android phones and iPhones. A tiny chip inside a heart-rate monitor has a very small memory, and its program must switch one particular pin on and off at exactly the right moment.

Think it through

Which kind of language would you choose for each program, and why?

Show what happens

For the phone game, a high-level language: the source code can be translated for different CPUs, and it is much quicker to write and correct. For the chip in the monitor, a low-level language may be better, because it can manipulate that particular pin and the small memory directly, and the chip is only ever one kind.

Your choices followed four trade-offs, and each one favours one kind of language. Test your understanding by deciding which kind of language each statement describes.

Does each statement describe a high-level language or a low-level language? Type high or low.
StatementHigh or low?
Easier to read and write, because it is closer to human language
A program written in it only works on one type of CPU
The same source code can be translated to run on different types of computer
Can control particular registers and memory locations directly
Mistakes are easier to find, because the code is readable
Hard to read, and a long program is hard to correct
One statement can stand for many machine-code instructions

    Show the completed table
    StatementHigh or low?
    Easier to read and write, because it is closer to human languagehigh
    A program written in it only works on one type of CPUlow
    The same source code can be translated to run on different types of computerhigh
    Can control particular registers and memory locations directlylow
    Mistakes are easier to find, because the code is readablehigh
    Hard to read, and a long program is hard to correctlow
    One statement can stand for many machine-code instructionshigh

    Low-level does not mean worse or simpler: it means closer to the machine. It gives control over the hardware at the cost of being harder to write, to read and to correct, and of working on only one kind of CPU. And a high-level program is never run directly by the CPU: it always has to be translated into machine code first.

    Apply it

    A team writes a device driver for one particular make of graphics card, and needs to control the card’s hardware directly. Which choice is best justified?
    Show the answer

    Answer: C. Assembly or machine code, because it controls that hardware directly and the driver is for one card only.

    Direct control of one kind of hardware favours a low-level language.

    Stage: Discover

    Words for the CPU’s instructions

    Look back at the three versions of the calculation. A person finds the machine code 0001 0100 almost impossible to remember, but finds LOAD 4 easy.

    Think it through

    Without being told, what do you think the assembly instruction ADD 5 asks the CPU to do, and how could a program turn it into 0s and 1s?

    Show what happens

    It asks the CPU to add the contents of address 5 to the value in the accumulator. To turn it into binary, a program could look up the word ADD in a table of instruction codes and write down the code, followed by the number 5 in binary.

    Assembly language is a low-level language in which each machine-code instruction is written as a short word called a mnemonic, such as LOAD, ADD or STORE, followed by what it uses. A mnemonic is easier to remember than a pattern of bits. Each assembly instruction is turned into exactly one machine-code instruction.

    The CPU cannot carry out mnemonics, so a program called an assembler translates an assembly language program into machine code. An assembler is one kind of translator, a program that converts code written in one language into machine code.

    In the made-up computer used here, each instruction is 8 bits: a 4-bit instruction code, then a 4-bit number.

    MnemonicInstruction code
    LOAD0001
    ADD0010
    SUB0011
    STORE0100

    Do the assembler’s job: use the table to translate each instruction, working from the mnemonic to the code and from the number to 4 bits.

    Translate between assembly language and machine code (the made-up computer above).
    Assembly languageMachine code
    LOAD 5
    ADD 6
    SUB 3
    STORE 7
    0001 0010
    0100 1000

      Show the completed table
      Assembly languageMachine code
      LOAD 50001 0101
      ADD 60010 0110
      SUB 30011 0011
      STORE 70100 0111
      LOAD 20001 0010
      STORE 80100 1000

      Check your understanding

      What does an assembler do?
      Show the answer

      Answer: B. It turns each assembly language instruction into one machine-code instruction.

      An assembler translates assembly language into machine code.

      Stage: Predict

      Two ways to translate

      At a conference, a speaker talks in French to an audience that understands only English. There are two ways to translate. An interpreter stands beside the speaker and says each sentence in English straight after it is spoken. A translator takes the whole written speech away, translates all of it, and hands back a finished English copy.

      Think it through

      Compare the two ways. Which one starts sooner? What happens if there is a sentence that cannot be translated? And what is it like if the speech is to be given again?

      Show what happens

      The beside-the-speaker method starts at once, but if it meets a sentence it cannot translate it stops there, after the earlier sentences have been translated, and the translator must be there each time the speech is given. The take-it-away method makes the audience wait, but it finds every problem in the whole speech, and then leaves a finished copy that can be used again and again without the translator.

      These two ways are how high-level programs are translated.

      A compiler translates the whole source code at once, before any of it runs, and produces an executable file of machine code. If it finds errors, it gives an error report for the whole code. Running the program means running the executable: the compiler does not run it.

      An interpreter translates and executes the code line by line: it translates one line, carries it out, then moves to the next. It produces no executable file. When it finds an error it stops and reports it.

      The same short program shows the difference. Its third line has a mistake: the statement is unfinished.

      OUTPUT "Start"
      Total ← 5 + 3
      OUTPUT Total +
      OUTPUT "End"
      The program above, handled by a compiler

      A compiler looks at the whole program before anything runs.

      1. Compiler

        Step 1 of 4: The whole source code is read

        The compiler reads all four lines before running anything.

      2. Compiler

        Step 2 of 4: The mistake is found

        It finds the unfinished statement on line 3.

      3. Compiler

        Step 3 of 4: An error report is given

        The compiler reports every error it found in the whole code (here only one, on line 3) and produces no executable file.

      4. Programmer

        Step 4 of 4: Nothing has run

        The word Start was never displayed. The programmer corrects the code and compiles it again; only then is an executable produced, which runs as often as needed.

      The same program, handled by an interpreter

      An interpreter translates and runs one line at a time, so it does some of the work before it reaches the mistake.

      1. Interpreter

        Step 1 of 4: Line 1 is translated and run

        The word Start is displayed on the screen.

      2. Interpreter

        Step 2 of 4: Line 2 is translated and run

        Total is set to 8.

      3. Interpreter

        Step 3 of 4: Line 3 has the mistake

        The interpreter cannot translate the unfinished statement, so it stops and reports the error.

      4. Programmer

        Step 4 of 4: Line 4 was never reached

        The program stopped on line 3, so “End” was not displayed. The programmer corrects line 3 and runs the program again, with the interpreter translating it again.

      A compiler does not run a program: it only translates it. The program runs afterwards, as the executable file, and no compiler is needed for that. An interpreter is different, because it translates the code every time the program is run.

      Stage: Explain

      Which translator would you choose?

      Does each statement describe a compiler or an interpreter? Type compiler or interpreter.
      StatementCompiler or interpreter?
      Translates the whole program before any of it runs
      Stops at the first error and has already run the lines before it
      Produces an executable file that runs without the translator
      The translator must be present every time the program runs
      Gives a report of all the errors it found in the code
      A few lines can be tested straight away, with no waiting for the whole program
      The finished program usually runs faster, because it is already machine code

        Show the completed table
        StatementCompiler or interpreter?
        Translates the whole program before any of it runscompiler
        Stops at the first error and has already run the lines before itinterpreter
        Produces an executable file that runs without the translatorcompiler
        The translator must be present every time the program runsinterpreter
        Gives a report of all the errors it found in the codecompiler
        A few lines can be tested straight away, with no waiting for the whole programinterpreter
        The finished program usually runs faster, because it is already machine codecompiler

        Do not confuse: Compiler and interpreter

        StrengthsCompiler
        The executable runs quickly and without the translator, and can be shared without giving away the source code.A finished game sold to customers.
        WeaknessesCompiler
        The whole program must be translated before any of it can be tried, and a long list of errors can be hard to work through. The executable suits one type of CPU.Waiting for a large program to compile after each small change.
        StrengthsInterpreter
        Part of a program can be run and tested straight away, and it stops at the line with the error, which helps to find it.A pupil trying out a new program line by line.
        WeaknessesInterpreter
        It is slower to run, because it translates as it goes, and the interpreter and the source code are both needed each time. Errors in later lines are not found until they are reached.Running a long program that is already finished.

        Stage: Apply

        Development and the final program

        A pupil is writing a program to organise a school quiz. While writing it, the pupil often changes a few lines and wants to try them. When it is finished, the school wants to give copies to ten other schools. Which translator suits each stage?

        1. Name what the stage needs. During development, the pupil needs to test small changes at once, and to find the line where something goes wrong.
        2. Match the translator. An interpreter runs the code line by line, so a change can be tried straight away, and it stops at the line with the error. So an interpreter suits development.
        3. Name what the final stage needs. The finished program must run quickly for other people, who should not need the translator or the source code.
        4. Match the translator. A compiler produces an executable file that runs without the translator, and it can be given to others without the source code. So a compiler suits the final program.

        That is why an interpreter is mostly used when a program is being developed, and a compiler for the final program.

        Apply it

        A group of beginners is writing short programs and often makes mistakes. They want to try a few lines at a time, and to see exactly where each program goes wrong. Which translator is best for them at this stage, and why?
        Show the answer

        Answer: C. An interpreter, because it runs line by line and stops at the line with the error.

        For developing and testing, an interpreter.

        Apply it

        A company has finished a game and will sell it to thousands of customers. Which statement best explains why it should be compiled?
        Show the answer

        Answer: A. The executable file runs without the compiler or the source code, and the program runs quickly.

        For the final program: an executable, run without the source code.

        Apply it

        A pupil says: “My compiler ran my program and then stopped at the error on line 3.” What is the most likely mistake in this account?
        Show the answer

        Answer: C. It describes an interpreter: a compiler translates all of it first, reports errors, and does not run.

        Running up to the error is interpreter behaviour.

        Stage: Discover

        Tools for writing code

        A pupil writes a program in a plain text editor. The pupil saves the file, opens a separate translator, runs it, reads a list of errors that give only line numbers, and goes back to the editor to find each one.

        Think it through

        What could be done to make this whole process faster and less error-prone for the pupil? Suggest two things a better tool could do.

        Show what happens

        For example: colour or highlight the code so that mistakes are easier to spot; suggest the rest of a word as the pupil types; put the translator and the output in the same place as the editor; and point to the line with an error and say what is wrong. These ideas are what an IDE offers.

        An integrated development environment (IDE) brings the tools for writing, translating, running and correcting code into one program. Its common functions are:

        • Code editor: a text editor made for code, with features such as line numbers and colours for the different kinds of word.
        • Run-time environment: a place to run the program and see what it does, often with tools to help find faults, such as running it a line at a time.
        • Translators: a built-in compiler or interpreter, so the code can be translated and run at the press of a button.
        • Error diagnostics: finding mistakes in the code, and showing where they are and what is wrong.
        • Auto-completion: suggesting the rest of a keyword or a variable name while it is being typed, so it is quicker to type and has fewer typing mistakes.
        • Auto-correction: fixing, or offering to fix, small mistakes automatically, such as a missing closing bracket.
        • Prettyprint: laying the code out neatly, with colour for keywords and indentation that shows its structure, so it is easier to read. Compare:
        FOR Index ← 1 TO 3
        OUTPUT Index
        NEXT Index
        
        FOR Index ← 1 TO 3
            OUTPUT Index
        NEXT Index
        Which function of an IDE does each description fit? Type one of: editor, run-time, translator, diagnostics, completion, correction, prettyprint.
        DescriptionIDE function
        The IDE draws a red line under line 12 and says that a bracket is missing
        The pupil types “pri” and the IDE offers to finish the word as print
        The code is indented and coloured so that its structure is easy to see
        The IDE adds the missing closing bracket for the pupil
        A Run button starts the program and its output appears in a panel
        The code is turned into machine code without leaving the IDE

          Show the completed table
          DescriptionIDE function
          The IDE draws a red line under line 12 and says that a bracket is missingdiagnostics
          The pupil types “pri” and the IDE offers to finish the word as printcompletion
          The code is indented and coloured so that its structure is easy to seeprettyprint
          The IDE adds the missing closing bracket for the pupilcorrection
          A Run button starts the program and its output appears in a panelrun-time
          The code is turned into machine code without leaving the IDEtranslator

          Apply it

          Ravi says: “An IDE is just another word for a compiler.” What is the best reply?
          Show the answer

          Answer: A. An IDE is a program for writing and running code; it contains a translator and other tools such as an editor.

          An IDE contains a translator, but does more.

          Stage: Consolidate

          Show what you know

          Think it through

          A pupil has written a program in a high-level language and wants other people to be able to run it. Explain the route from the source code to the CPU carrying it out, for a compiler and for an interpreter, and say which you would use for the final program.

          Show a model answer

          A good answer covers both and chooses. For example: “The source code is in a high-level language, which the CPU cannot run. A compiler translates the whole of it into machine code before it runs, as an executable file, which is then run by the CPU, with an error report if there are mistakes. An interpreter translates and runs it one line at a time, and stops at an error, so it has to be there every time. For the final program I would compile it, so that other people receive a fast executable and do not need the translator or the source code. An interpreter is better while I am still writing and testing.”

          Check your understanding

          Which statement about translators is correct?
          Show the answer

          Answer: C. An assembler translates assembly language into machine code.

          Assembler: assembly language to machine code.

          • The CPU can only carry out machine code. Anything else has to be translated.
          • A high-level language is readable, easier to write and debug, and independent of the CPU. A low-level language (assembly language and machine code) is tied to one type of CPU and hard to read, but can control the hardware directly.
          • Assembly language writes each instruction as a mnemonic, such as LOAD. An assembler translates it into machine code.
          • A compiler translates the whole program before it runs, producing an executable file and reporting all the errors it finds. An interpreter translates and runs it line by line and stops at the first error.
          • An interpreter is mostly used while developing a program; a compiler is used for the final program.
          • An IDE brings the tools together: code editor, run-time environment, translators, error diagnostics, auto-completion, auto-correction and prettyprint.

          Sources and scope

          • What this lesson is. The tenth lesson of the Computer Systems module, written for this site. It teaches Cambridge IGCSE Computer Science (0478) point 4.2 (2026 to 2028, version 6): high-level and low-level languages, assembly language, compilers and interpreters, and IDEs. Its curriculum links are provisional and imply no endorsement by any examination board. It has not been approved by the site owner.
          • Original material. The made-up computer with 8-bit instructions and its instruction codes, the four-line program with the unfinished statement, the quiz program and the people named are fictional and were written for this lesson. The programs are in Cambridge pseudocode, or in the made-up assembly language.
          • Simplified on purpose. Real instruction sets are far larger and encode instructions in many different ways. Real compilers work in several stages, and many modern languages are translated to an intermediate form first and then run by a program that is both a compiler and an interpreter; the lesson keeps to the course’s two simple models. Real compilers report errors in different ways, and some also stop after a number of errors.