← GCSE Computer Science · OCR · GCSE Computer Science revision
⭐ 0
OCR GCSE Computer Science (J277) · 2.5 Programming languages and IDEs
Mini-Lesson

Programming languages and IDEs

3 missions. Guess, learn, then check. Your place is saved.

  1. Mission 1Why write a 1999 hit game almost entirely in assembly?
  2. Mission 2Why do some languages show all your errors, and others just one?
  3. Mission 3How can a program tell you which line your bug is on?
Mission 1

Why write a 1999 hit game almost entirely in assembly?

Make a guess: Why write a 1999 hit game almost entirely in assembly?

Languages · levels of programming language

What the processor actually runs

Machine codeopcodeoperand000101000011010100100110CPUillustrative 8-bit instruction set(not a real processor)
  • A CPU can only execute machine code: instructions in binary.
  • Each instruction is a simple step, such as load a value, add, store a result or jump.
  • Each processor family has its own instruction set, so machine code for one family won't run on another.
  • Machine code and assembly language are low-level languages: they work directly with the processor's own instructions.
Languages · levels of programming language

Assembly language

Assembly to machine codeAssemblyMachine codeLDA price00010100ADD tax00110101STA total00100110assembler
  • Assembly language replaces binary with short mnemonics such as LDA (load), ADD and STA (store).
  • Each assembly instruction matches exactly one machine code instruction: a 1:1 correspondence.
  • Like machine code, it is specific to one processor family.
Assembly language (illustrative)
LDA price    ; load price into the processor
ADD tax      ; add tax to it
STA total    ; store the result in total
Languages · levels of programming language

High-level languages

  • High-level languages use English-like keywords and maths-style expressions.
  • One statement often becomes several machine code instructions: the line below becomes the three assembly instructions you just met.
  • They are machine independent: the same source code can be translated to run on different processor families.
  • A compiler or interpreter must translate the code before the CPU can run it.
  • Most programs are high-level: they are quicker to write, read and debug.
OCR Exam Reference Language
total = price + tax
Quick check
?A programmer writes the line STA total. What kind of code is this?
Calculate
?An assembly program has these 3 lines: LDA price, ADD tax, STA total. How many machine code instructions will it become?
Languages · levels of programming language

Choosing a level

Levels of languageeasier for humanscloser to the hardwareHigh-leveltotal = price + taxAssemblyLDA price ADD tax STA totalMachine code0001 0100 0011 01010010 0110low-level
High-levelLow-level
Reading and writingeasier: English-likeharder: mnemonics or binary
Debuggingeasier to find and fix errorsharder
Portabilitymachine independentworks on one processor family
Hardware controlindirect, through the OSdirect control of registers and memory
Speed and memorytranslated code may be less efficientcan be very fast and compact
  • Use low-level for device drivers, embedded systems and code where speed or memory is critical.
  • Use high-level for most applications, where quick development matters more.
Quick check
?A smart thermostat has a tiny chip with very little memory, and its program must control a temperature sensor directly. Which level of language suits it best?
Mission check

?Why write a 1999 hit game almost entirely in assembly?
Mission 2

Why do some languages show all your errors, and others just one?

Make a guess: Why do some languages show all your errors, and others just one?

Languages · translators

Why translate?

TranslatorsSource codeTranslator0110 10111001 0010Machine codeCPUHigh-levelCompilerHigh-levelInterpreterAssemblyAssembler
  • The CPU can only execute machine code, so the source code that programmers write must be translated first.
  • A translator is a program that converts source code into a form the CPU can execute.
  • High-level code is translated by a compiler or an interpreter.
Languages · translators

Compiler or interpreter?

Compiler and interpreterCompiler8 linestranslateEXEexecutablerunInterpreterline 1translaterunline 2translaterunline 3translaterun… and so on, one line at a time, to line 8
  • A compiler translates the whole program before it runs, producing an executable file of machine code that runs without the compiler.
  • An interpreter translates and runs the code one line at a time. It is needed every time the program runs.
  • Errors: a compiler gives an error report for the whole program; an interpreter stops at the first error.
Quick check
?An 8-line program has errors on lines 4 and 7. What happens when you run it with an interpreter?
Languages · translators

Choosing a translator

When each is usedInterpreterwhile developingeditrunfixCompilerfor releasereleaseEXEusers
CompilerInterpreter
Translatesthe whole program, before it runsone line at a time, as it runs
Producesan executable fileno executable file
Running speedfast: already translatedslower: translated again every run
Finding errorsreport after translating everythingstops at the error, easy to see where
After a changemust recompile the whole programjust run it again
Sharingsend the executable; source stays privateusers need the source and an interpreter
  • An interpreter is mostly used while developing and testing a program; a compiler translates the final program for release.
Quick check
?A games studio is ready to release its finished game and doesn't want players to see its source code. Which translator should it use?
Mission check

?Why do some languages show all your errors, and others just one?
Mission 3

How can a program tell you which line your bug is on?

Make a guess: How can a program tell you which line your bug is on?

Languages · IDEs

One program for writing, running and fixing code

An IDEIDE▶ Run1total = 02for i = 1 to 33 total = total + i4next i5print(total)run-time environmenterrorstranslator
  • An Integrated Development Environment (IDE) is software that puts tools for writing, translating, running and debugging code in one place.
  • The editor is where you write and edit code. It shows line numbers, colours keywords and indents code automatically, so code is easier to read.
Languages · IDEs

Translate, run and diagnose

  • The IDE includes a translator, so you can compile or interpret your code with one click.
  • The run-time environment runs your program inside the IDE: you see its output and enter input, and if it crashes the IDE shows what went wrong.
  • Error diagnostics report each error with a message and its line number, and highlight that line.
Calculate
?You run this program in an IDE. Which line number will the error diagnostics highlight?
OCR Exam Reference Language
total = 0
for i = 1 to 3
    total = total + i
nxt i
print(total)
Languages · IDEs

Debugging tools

DebuggingIDEStep▶ Run1total = 02for i = 1 to 33 total = total + i4next i5print(total)watchi = 2total = 1Paused at line 3red dot = breakpointstep: run one line at a time
  • A breakpoint pauses the program at a chosen line, before that line runs.
  • Stepping runs the program one line at a time, so you can follow the path it takes.
  • A variable watch shows the current value of chosen variables while the program runs.
Calculate
?The corrected program below has a breakpoint on line 3 and a watch on total. The program pauses each time it reaches line 3. What does the watch show for total at the third pause?
OCR Exam Reference Language
total = 0
for i = 1 to 3
    total = total + i
next i
print(total)
Quick check
?A classmate's long program has no indentation and is hard to follow. Which IDE feature helps most?
Mission check

?How can a program tell you which line your bug is on?
Recap

Big ideas

  • The CPU only runs machine code (binary); assembly uses mnemonics with a 1:1 match to machine code. Both are low-level and tied to one processor family.
  • High-level languages are easier to write, read and debug and are machine independent, but must be translated.
  • Low-level suits device drivers, embedded systems and speed-critical code; high-level suits most applications.
  • Source code must be translated before the CPU can run it: a compiler translates the whole program into an executable; an interpreter translates and runs it line by line.
  • Interpreters suit development and testing; compilers suit the final program.
  • An IDE puts an editor, a translator, a run-time environment and error diagnostics in one program.
  • Editor features such as line numbers, colour coding and automatic indentation make code easier to write and read.
  • Breakpoints, stepping and variable watches help you find logic errors while the program runs.
🏆

Mini-lesson complete!

⭐⭐⭐

You've worked through Programming languages and IDEs for OCR GCSE Computer Science (J277). 🎉

  1. Mission 1Why write a 1999 hit game almost entirely in assembly?
  2. Mission 2Why do some languages show all your errors, and others just one?
  3. Mission 3How can a program tell you which line your bug is on?

Your stars: 0 / 0

Next: test yourself in the Verify stage.

📣 Smashed it? Share your score

Challenge a mate to beat your stars, or show a parent how you got on.

→ Back to GCSE Computer Science · OCR

Specification points and sources for this lesson are listed at the bottom of the page.

Sources (6)

The specification points and sources behind this lesson.

  1. 1 OCR J277 spec v3.1, 2.5.1
  2. 2 OCR J277 spec v3.1, 2.5.2
  3. 3 OCR J277/02 mark scheme, June 2023, Q5(a)(iii), https://www.ocr.org.uk/Images/704883-mark-scheme-computational-thinking-algorithms-and-programming.pdf
  4. 4 Chris Sawyer (the game's creator), official site: FAQ "Chris Sawyer Software Development", Q "What language was RollerCoaster Tycoon programmed in?" ("99% written in x86 assembler/machine code … with a small amount of C code used to interface to MS Windows and DirectX"), https://chrissawyergames.com/faq3.htm; release "early in 1999": https://chrissawyergames.com/info.htm
  5. 5 Atari (publisher of the RollerCoaster Tycoon series), "Interview with RollerCoaster Tycoon's creator Chris Sawyer", Atari's own Medium publication Atari Club, Carly Francis, 27 March 2024; Sawyer's own answer to "Why did you write RollerCoaster Tycoon in assembly language … rather than a high level language like C?", https://medium.com/atari-club/interview-with-rollercoaster-tycoons-creator-chris-sawyer-684a0efb0f13
  6. 6 PCGamesN, "RollerCoaster Tycoon: the best-optimised game of all time?", https://www.pcgamesn.com/rollercoaster-tycoon/code-chris-sawyer