4 missions. Guess, learn, then check. Your place is saved.
Mission 1Why write a 1999 hit game almost entirely in assembly?
Mission 2Why do some languages show all your errors, and others just one?
Mission 3How can a program tell you which line your bug is on?
Mission 4It passed every test. So why did it fail for an 18-year-old?
The specification points and sources are listed under the lesson: see Sources.
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
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 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.
An assembler translates assembly language into machine code.
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.
Eduqas pseudo-code
set 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
High-level
Low-level
Reading and writing
easier: English-like
harder: mnemonics or binary
Debugging
easier to find and fix errors
harder
Portability
machine independent
works on one processor family
Hardware control
indirect, through the OS
direct control of registers and memory
Speed and memory
translated code may be less efficient
can 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?
Assembly gives the programmer direct control of the processor's own instructions, so the code can be very fast and compact. Its creator said a high-level language would have run too slowly on the PCs of 1999, or forced a simpler game. The price was code that is much harder to write, read and debug.
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?
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.
Assembly is translated by an assembler: each assembly instruction becomes one machine code instruction.
Languages · translators
Compiler or interpreter?
A compiler translates the whole program before it runs, producing an executable file of machine code that runs without the compiler.
An interpreter translates one line at a time into machine code and runs it. 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
Compiler
Interpreter
Translates
the whole program, before it runs
one line at a time, as it runs
Produces
an executable file
no executable file
Running speed
fast: already translated
slower: translated again every run
Finding errors
report after translating everything
stops at the error, easy to see where
After a change
must recompile the whole program
just run it again
Sharing
send the executable; source stays private
users 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.
An assembler is used when a program is written in assembly, e.g. for embedded systems or device drivers.
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?
Languages · translators
Inside a compiler
Lexical analysis: comments and spaces are removed; keywords, constants and identifiers become tokens; a symbol table of variables, labels and subroutines is built.
Syntax analysis: tokens are checked against the grammar rules; syntax errors are reported.
Semantic analysis: checks the code makes sense, e.g. data types suit the operations.
Code generation: machine code is produced.
Code optimisation: the code is made faster or to use fewer resources.
Languages · translators
Types of programming error
Error
What goes wrong
Example
Syntactical
code breaks the language's rules, so it won't translate
ouptut total
Logical
the program runs but gives the wrong result
< used instead of <=
Run-time (execution)
the program crashes while running
dividing by zero
Linking
a library or subroutine the code calls can't be found
a missing library file
Rounding
a value is rounded, so it loses accuracy
0.1 + 0.2 gives 0.30000000000000004
Truncation
digits are cut off, not rounded
7.9 stored as an integer becomes 7
Quick check
?A program stores 2 ÷ 3 to 2 decimal places as 0.67. Adding three of these values gives 2.01 instead of 2. Which type of error is this?
Mission check
?Why do some languages show all your errors, and others just one?
A compiler translates the whole program before it runs, so it can list every error it finds in one report. An interpreter translates and runs one line at a time, so it stops as soon as it reaches the first error.
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 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 provides automatic line numbering, automatic colour coding of keywords and automatic formatting (indentation), so code is easier to read.
Statement completion suggests how to finish a statement as you type.
Languages · IDEs
Translate, run and diagnose
The IDE includes a translator, so you can compile or interpret your code with one click.
Error diagnostics report each error with a message and its line number, and highlight that line.
Syntax error detection marks code that breaks the language's rules, often as you type.
Calculate
?You run this program in an IDE. Which line number will the error diagnostics highlight?
Eduqas pseudo-code
set total = 0
for i = 1 to 3
set total = total + i
nxt i
output total
Languages · IDEs
Debugging tools
A break point pauses the program at a chosen line, before that line runs.
Trace 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.
A memory inspector shows the contents of the memory locations the program is using.
These are features of the debugger.
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?
Eduqas pseudo-code
set total = 0
for i = 1 to 3
set total = total + i
next i
output total
Languages · IDEs
Building the final program
Libraries are collections of ready-written, tested code for use in your own programs.
They hold routines/subroutines and standard functions, e.g. to find the length of a string.
The linker joins your translated code and the library routines it uses into one executable file.
The loader copies the executable from storage into RAM so it can run.
Code optimisation makes the translated code faster or use less memory.
Quick check
?Your program calls a sorting routine from a library. Which tool joins that routine to your translated code to make one executable?
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?
The IDE translates your code, and when the translator (or the running program) hits a problem, the error diagnostics report a message with the line number. Because the editor numbers every line, you can go straight to the bug.
Mission 4
It passed every test. So why did it fail for an 18-year-old?
Make a guess: It passed every test. So why did it fail for an 18-year-old?
Programming · testing
Why test?
Testing checks that a program works as intended and meets its requirements.
It finds errors so they can be fixed before users meet them.
A program can run without crashing and still give wrong results.
Passing a few easy tests proves little: choose test data that could expose errors.
Programming · testing
Normal, edge and wrong data
For a program that accepts whole numbers from 1 to 10:
Typical data: sensible values that should be accepted, e.g. 5.
Extreme data: the smallest and largest acceptable values, 1 and 10.
Erroneous data: data that should be rejected, e.g. ten, −3 or 3.14.
Calculate
?The rule is "adult ticket for 18 and over". Tests with ages 10, 30 and 50 all gave the right ticket. Which single age would show the error?
Eduqas pseudo-code
input age
if age > 18
output "Adult ticket"
else
output "Child ticket"
end if
Quick check
?A program accepts whole numbers from 1 to 10. A tester types the word ten. What type of test data is this?
Programming · testing
Types of error
A syntax error breaks the rules of the language, e.g. a missing bracket. The program cannot be translated or run.
A logic error lets the program run, but it gives the wrong or unexpected result, e.g. > where ≥ was needed.
A runtime error happens while the program runs and makes it crash, e.g. dividing by zero or using an index past the end of an array. Eduqas calls this a run-time or execution error.
Testing with good test data is how you find logic errors.
Quick check
?A program should output the average of three marks, 60, 70 and 80. It runs, but outputs 156.67 because the code says a + b + c / 3. What kind of error is this?
Programming · testing
Test plans
A test plan lists each test before it is run: what it tests, the test data, its type and the expected result.
After running, record the actual result. If they differ, fix the code and test again.
Test
Data
Type
Expected
Actual
1
5
Typical
Accepted
Accepted
2
10
Extreme
Accepted
Rejected
3
11
Erroneous
Rejected
Rejected
4
ten
Erroneous
Rejected
Rejected
Test 2 failed, so the range check needs fixing.
Programming · testing
Code that is easy to maintain
Other people (and you, later) must be able to read and change code. This is maintainability.
Self-documenting identifiers: totalScore, not t.
Annotation (comments) explain what each part of the code does.
Indentation shows which lines belong inside loops, selection and subprograms.
White space and a clear layout split code into readable blocks.
Subroutines with well-defined interfaces break code into named, reusable parts.
Mission check
?It passed every test. So why did it fail for an 18-year-old?
The code used > 18 when the rule needed ≥ 18, a mistake that only shows at exactly 18. Testing 10, 30 and 50 only tried normal values; a test at the edge of the range would have caught it.
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; assemblers translate assembly language.
A compiler works in stages (lexical, syntax and semantic analysis, code generation, optimisation), and errors range from syntax to rounding and truncation.
An IDE puts an editor, a translator, debugging tools and error diagnostics in one program.
Editor features such as line numbers, colour coding and automatic formatting and statement completion make code easier to write and read.
Breakpoints, trace and variable watches help you find logic errors while the program runs.
Choose test data of every kind: normal, at the edges of the range, and data that should be rejected (typical, extreme, erroneous).
Syntax errors stop a program running; logic errors give wrong results; runtime errors crash it while it runs.
Meaningful names, comments, indentation and subprograms make code easy to maintain.
🏆
Mini-lesson complete!
⭐⭐⭐
You've worked through Languages, translators and IDEs for Eduqas GCSE Computer Science. 🎉
Mission 1Why write a 1999 hit game almost entirely in assembly?
Mission 2Why do some languages show all your errors, and others just one?
Mission 3How can a program tell you which line your bug is on?
Mission 4It passed every test. So why did it fail for an 18-year-old?
5 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
6 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