Programming Languages

High vs Low Level Language

There are two main types of programming language:

  1. High-Level (e.g. Python)
  2. Low-Level (e.g. Machine Code)

Machine Code is instructions written in binary, where one instruction relates to one thing that the computer needs to do e.g. fetch a piece of data from memory. Low Level languages are those that are extremely close to machine language. This means that the syntax (symbols and words they use) are quite far away from human language but the instructions have a 1-1 correspondence to machine code.

High Level languages are those that are relatively easy for programmers to use, as they involve a large amount of English language. One command in a high level language will relate to several in a low level one. Using high level languages, allows programmers to write applications that are portable (i.e. transferrable) across devices and different platforms. Computers can only understand Machine Code, so all higher-level programming languages must be translated before the computer can understand them.


Low LevelHigh Level
UseUsed for developing new operating systems or writing firmware codes for micro-controllers.Used to write creative software, which can run on multiple platforms and architecture. Most computer programs are written in high-level code.
SpeedSince low-level languages are nearer to machine code, they are fast to process.These are slower to process as they have to be translated through several layers of code before reaching the hardware.
PortabilityThese are specific to the piece of hardware they are written for, and cannot be run on any other hardware.These can be easily moved across devices and platforms.
Ease of useVery challenging and requires a great deal of knowledge and experience.Relatively straightforward and can be debugged in a much easier manner than in low-level languages.

The main difference is that it is much easier to for people to program in higher level languages, but they give you less control over how exactly your program runs, and take time to be translated into machine code so that computers can understand it.

Translators

High-level programming languages and assembly language must be translated into machine code before it can be understood.

There are three common types of program translator:

  1. Assembler
  2. Compiler
  3. Interpreter

Assembler

An assembler converts assembly source code into machine code.

Compiler

A compiler translates the whole program into machine code before the program is run. The machine code is saved and stored separately to the high-level code.

Interpeter

An interpreter translates code into machine code, instruction by instruction - the CPU executes each instruction before the interpreter moves on to translate the next instruction. If it comes across an error in the code, the program will stop running. An interpreter does not create an independent final set of object code__ __- object code is created each time it runs.

Low Level Languages

The two-examples of low-level language you need to know about are machine code and assembly language

Machine code is expressed in binary whilst assembly language uses characters as well. Machine code is the only language directly executable by processors. Every processor has it’s own specific machine code instruction set.

Assembly language must be translated by an assembler for the computer to understand it, but has a 1:1 correspondence with machine code - one instruction in assembly language corresponds to one instruction in machine code. This means that assembly language is also specific to a processor or family of processors, and can’t be used across different pieces of hardware. Assembly language is often used to develop software for embedded systems and for controlling specific hardware components.

The reason for using assembly language over machine code, is that assembly language is easier for programmers to read and debug, and they are less likely to make mistakes when writing instructions in assembly language.

For each statement, write whether it is true or false:

Machine code is written in binary.
True
Assembly language can be directly understood by the computer.
False
Explanation: Assembly language must be translated to machine code first.
High level language can be used on multiple devices running different hardware.
True
Explanation: An advantage of high level language is that it is portable.
High level language is used to create firmware for micro-controllers.
False
Explanation: Low level language is used for this, as it is faster to run.
Low level language is slower to process than high level as there are more lines of code to process.
False
Explanation: Low level language is much faster to process as it is much closer to machine code, whilst high-level language has to go through several translations first.
High level language is much closer to human language, and contains words for commands.
True
Explanation: High level languages are ones like python where one written command is equivalent to several machine code ones.
Assembly language is better to code in than machine code because it's easier for the computer to understand.
False
Explanation: Assembly code is easier for *humans* to understand, so they are less likely to make mistakes.

Comparisons Between Translators

There are many reasons to choose an interpreted or compiled language over the other.

Advantages of Interpreters

  1. The file that needs to be run can be transferred between machines. For example, some elements of interactive webpages use an interpreted language, because they can be sent and translated to any machine, regardless of the hardware being used on them.
  2. They are easy to test and debug, as an interpreted program will stop when it finds an error, and report where that error was.
  3. Doesn’t require compiling each time, which makes it quicker to run the file when testing.

Advantages of Compilers

  1. From the compiled machine code file that the compiler creates, the program is much quicker to run.
  2. There is no need for a translator for the program to run each time.
  3. The final program can’t be changed from the source code file, as the person running the program is only provided with the compiled machine code. Most importantly, this means that the original source code file is private, which is very useful when creating commercial programs.

For each scenario which translator (assembler, compiler or interpreter) would be most appropriate?

Writing new firmware for a micro-controller.
assembler
Explanation: Assembly language is used for creating firmware for micro-controllers.
Creating a new piece of software that will be sold for profit.
compiler
Explanation: Compiled languages hide the source code from the user.
A program that will be run regularly without being changed.
compiler
Explanation: Compiled languages are faster to run from the (compiled) machine code file.
Writing a program that will be regularly updated before running.
interpreter
Explanation: Interpreted languages are quicker to run from the original high-level language than compiled languages - compiling can take some time.
Testing out an algorithm to do a particular task.
interpreter
Explanation: Interpreted languages are much easier to test and debug.