Why does a program written in a high-level language need to be translated before it can be executed?

In order to continue enjoying our site, we ask that you confirm your identity as a human. Thank you very much for your cooperation.

  show understanding of the need for both high-level and low-level languages

•  show understanding of the need for compilers when translating programs written in a high-level language

•  show understanding of the use of interpreters with high-level language programs

•  show understanding of the need for assemblers when translating programs written in assembly language

Why does a program written in a high-level language need to be translated before it can be executed?

The only language understood by computers is binary, also known as machine code

This is because computers are electronic devices that can only tell the difference between the on and off states of an electric circuit. 

The numbers 1 and 0 are used by humans to represent these on/off values. That’s why things written in binary look like this: 01010010010001010101011001001001010100110100010100100001

Machine code:

  •  Instructions for a computer to follow must therefore be written in machine code
  • This was done by early computer programmers
  • Each sort of computer is different so they all need different binary instructions to perform the same task – different computers have different machine code

Programming languages can be classified into low-level and high-level languages

Low-level languages

Assembly:

 To make it easier to program computers a programming language was invented. It was called ‘Assembly‘ and was made up of a small set of command words called mnemonics which programmers typed instead of binary Examples of mnemonics are “MOV”, “ADD” and “PUSH”

Computers could not understand Assembly so it had to be converted to machine code by an ‘assembler‘before it could be run

  • Low-level languages are more similar to machine code than they are to languages spoken by humans
  • They are not very developed and just offer quicker ways to write binary
  • This means they give the programmer close control over the computer because their instructions are very specific
  • Unfortunately they are hard to learn
  • Since the machine code for each computer is different, programs translated to machine code on one computer will not work on a different one: Low level languages are not very ‘portable’

High-level languages

High level programming languages are more developed than low-level languages so are closer to human spoken language

  • Some examples of high level languages are: C#, Visual Basic, C, C++, JavaScript, Objective C, BASIC and Pascal (the fact that they all have the letter C in their name is a coincidence. Some do not.)
  • High-level programming languages are easier for humans to write, read and maintain
  • They support a wide range of data types
  • They allow the programmer to think about how to solve the problem and not how to communicate with the computer. This is called abstraction

Converting to Machine Code

 Translators:

  • Just like low-level languages, high-level languages must be converted to machine code before a computer can understand and run them
  • This is done using a ‘translator‘
  • Different translators convert the same high level code into machine code for different computers
  • High level code ready to be translated into machine code is called ‘source code’

There are two different types of translator: Compilers and Interpreters

Compilers:

  • Compilers convert (or ‘compile’) the source code to machine code all at once
  • This is then stored as an executable file which the computer can run (for example, something ending with the ‘.exe’ file extension)
  • Errors in the source code can be spotted as the program is compiling and reported to the programmer

Interpreters:

  • Interpreters convert the code as it is running
  • They take a line of source code at a time and convert it to machine code (which the computer runs straight away)
  • This is repeated until the end of the program
  • No executable file is created
  • If the interpreter comes across an error in the source code the only things it can do is to report the error to the person trying to use the program (or it may just refuse to continue running)

Show understanding of the need for both high-level and low-level languages

Computers don’t understand high level languages because they only understand binary (‘machine code’). 

Humans struggle to understand exactly what a program does when it is in binary only.

High-level languages are more accessible to programmers.

High-level languages will work on different types of computers.

Low-level programming allows for hardware to be controlled directly.

Low-level programming will only work with the processor it is designed for (machine-dependent).

understand the need for compilers when translating programs written in a high-level language 

Translates the entire program from source (i.e. high-level language) to object code / machine code.

Produces an executable file (i.e. In binary / machine code)

Source code remains hidden so cannot be modified by customer

Compiled once only so doesn’t need a translator

Compilers use a lot of computer resources: It has to be loaded in the computer’s memory at the same time as the source code and there has to be sufficient memory to hold the object code

Difficult to pin-point errors its source in the original program.

Show understanding of the use of interpreters with high-level language programs

Interpreters translate each instruction is taken in turn and translated to machine code. The instruction is then executed before the next instruction is translated.

Error messages are output as soon as an error is encountered so easy to debug

Useful for prototypes as program will run even when part of it has errors.

Execution of a program is slow compared to that of a compiled program.

Instructions inside a loop have to be translated each time the loop is entered.

Understand the need for assemblers when translating programs written in assembly language

Assemblers translate assembly language to machine code / binary / object code.