Teach Any Computer Science Class
We have put together a full GCSE Computer Science curriculum that will give you all the teaching materials you need to teach any topic.
Whether you're a brand new Computer Science teacher, or you've been teaching ICT for years, our resources will save you hours and hours of lesson preparation every single week.View the Lessons →
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.
secondBig LDA second
1 STA 12
3 STA 13
4 SUB 12
5 BRP 9
6 LDA 12
8 BRA 11
9 LDA 13
12 DAT 0
13 DAT 0
- 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.
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.
INPUT = 9, 5
OUTPUT = 9
INPUT = 5, 9
OUTPUT = 9