Topic 12 · Notes

Program construction

These notes are part of a subscription

5 sections covering the whole specification for this topic, with worked examples.

Preview

High-level and low-level languages

A CPU can only run machine code: instructions in binary. Programmers usually write in a language that is easier for people, which is then translated.

High-level languagesLow-level languages
ExamplesPython, Java, C#, Visual BasicMachine code (binary) and assembly language (mnemonics)
Looks likeEnglish words and maths: if score > 50Binary (10110000 01100001) or short codes (LDA 25)
One statementUsually becomes many machine code instructionsAssembly: one instruction becomes one machine code instruction
PortabilityPortable: the same code runs on different types of computer (with the right translator)Specific to one type of CPU: won't run on a different processor
Writing and debuggingEasier and quicker; easier to read and maintainHard and slow; easy to make mistakes
Control of hardwareLittle: memory is managed for youDirect: specific memory locations and registers
Speed and sizeTranslated code may be larger and slowerCan be very fast and small
TranslatorCompiler or interpreterAssembler (for assembly); machine code needs none

When to use each

Use a high-level language when …Use a low-level language when …
Writing most applications: games, websites, apps, business softwareWriting device drivers or parts of an operating system that control hardware directly
The program must run on different types of computerProgramming embedded systems with very little memory (e.g. a washing machine controller)
Development needs to be quick, and the code easy to maintainSpeed is critical and every instruction counts
A team of programmers will share the codeThe exact memory and registers used must be controlled

Also in these notes

  • Machine code and assembly language
  • Translators
  • Stages of compilation
  • Programming errors