GCSE Algorithms Resources (14-16 years)
- An editable PowerPoint lesson presentation
- Editable revision handouts
- A glossary which covers the key terminologies of the module
- Topic mindmaps for visualising the key concepts
- Printable flashcards to help students engage active recall and confidence-based repetition
- A quiz with accompanying answer key to test knowledge and understanding of the module
A-Level Introduction to programming (16-18 years)
- An editable PowerPoint lesson presentation
- Editable revision handouts
- A glossary which covers the key terminologies of the module
- Topic mindmaps for visualising the key concepts
- Printable flashcards to help students engage active recall and confidence-based repetition
- A quiz with accompanying answer key to test knowledge and understanding of the module
The following program will show the use of the BRP and BRA branch instructions in making decisions within a program.
Running the program: when prompted, INPUT two numbers and the program will OUTPUT the biggest number of the two.
INP STA first INP STA second SUB first BRP secondBig LDA first OUT BRA endProgram secondBig LDA second OUT endProgram HLT first DAT second DAT | 0 INP 1 STA 12 2 INP 3 STA 13 4 SUB 12 5 BRP 9 6 LDA 12 7 OUT 8 BRA 11 9 LDA 13 10 OUT 11 HLT 12 DAT 0 13 DAT 0 |
Instructions
- Copy the 14 line program above and paste it into the Program box.
- Click on the “Assemble Program” button.
- After the program is assembled you should see RAM addresses 0 to 11 contain the machine code instructions shown in the image.
- Click on the RUN button.
- If you have difficulty following what is happening, read the explanation below and use STEP instead of RUN so you can follow each step.
Explanation
first and second are used to label DAT instructions. DAT identifies the 13th and 14th instructions as data. The labels therefore refer to RAM addresses 12 and 13 (0-indexed counting).
0 INP //input the first value into the accumulator. 1 STA first //store the accumulator contents in RAM address 12 (labelled first). 2 INP //input the second value into the accumulator. 3 STA second //store the accumulator contents in RAM address 13 (labelled second). 4 SUB first //subtract the contents of RAM address 12 (labelled first) from the accumulator and store the result in the accumulator. 5 BRP secondBig //if the accumulator contains zero or a positive number then the 2nd number must be the biggest one so branch to the instruction at RAM address 9 (labelled secondBig) 6 LDA first //the contents of memory address 12 (labelled first) are loaded into the accumulator. 7 OUT //the value in the accumulator is sent to the OUTPUT. 8 BRA endProgram //branch to the instruction at memory location 11 (labelled endProgram). This makes the program jump past the lines that output second as the biggest number. 9 secondBig LDA second //the contents of memory address 13 (labelled second) are loaded into the accumulator. 10 OUT //the value in the accumulator is sent to the OUTPUT. 11 endProgram HLT //the program halts.
Example results
INPUT = 9, 5
OUTPUT = 9
INPUT = 5, 9
OUTPUT = 9