Community resourceWorksheet
OCR H446 1.2.4 LMC control flow: trace, amend and write
Part 4 of 10 · H446 1.2.4 · Types of programming language
Branch instructions turn a straight LMC listing into a decision or a loop, and H446 1.2.4 expects a program that behaves correctly on every permitted path. Following on from basic LMC tracing, this worksheet covers BRA, BRZ and BRP, repeated input within one execution, and the faults that appear when a halt or a comparison boundary is wrong.
Students will:
- decide which branch is taken from the accumulator value immediately before it
- trace a two-path program and record the single output produced before HLT
- trace one execution supplied with several inputs, recording each return to the start label and the final halt
- diagnose the fault caused by a missing HLT and state the repair
- amend and then write LMC routines that classify a boundary value correctly and halt on every path
Inside: 6 explanation cells, 1 multiple-choice question, 1 fill-in-the-blanks cell, 3 written answers and 2 trace tables. 21 marks, about 55 to 65 minutes.
Series: H446 1.2.4 · Types of programming language, part 4 of 10.
Shared by Coding PathwayVerified teacher
- 13 cells
- About 60 minutes
- CC BY-SA 4.0
- Shared 31 Aug 2026
- Updated 3 Sept 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
LMC control flow: trace, amend and write
Branch instructions turn a straight trace into a decision or loop. A correct program must work on every permitted path, output the right number of values and reach HLT.
Read a branch from accumulator state
BRA LABEL: always continue at LABEL.BRZ LABEL: branch only when the accumulator is zero.BRP LABEL: branch when the accumulator is zero or positive.
For a decision, identify the accumulator value immediately before the branch. For a loop, identify the value that changes and the condition that eventually ends repetition. Then test more than one input path.
Worked two-path program
INP
SUB LIMIT
BRP LARGE
LDA SMALLCODE
OUT
HLT
LARGE LDA LARGECODE
OUT
HLT
LIMIT DAT 10
SMALLCODE DAT 1
LARGECODE DAT 2
Input 7 produces accumulator −3 at BRP, so execution continues and outputs 1. Input 13 produces 3, branches to LARGE and outputs 2. Each path reaches a halt before the data declarations.
Trace the program for input 10. Pay attention to whether BRP includes zero and record the single output before HLT.
Record values only when they change. Record outputs in order and include the terminating state.
Use one row for each instruction carried out. Fill in a box only when that value changes on that row, and leave the rest blank. Put the address of the instruction being carried out in the Address column.
Input: "10"
INP01SUB LIMIT02BRP LARGE03LDA SMALL04OUT05HLT06LARGELDA BIG07OUT08HLT09LIMITDAT 1010SMALLDAT 111BIGDAT 2| Row | Address | ACC | Output |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 |
One execution can return for another input
A branch back to START does not restart the program or clear its memory. It changes the next instruction, so the following INP consumes the next supplied value during the same execution. Trace every return, output and final halt rather than treating each input as a separate run.
Trace one execution supplied with inputs 7, 12 and 0 in that order. Record both non-zero outputs, each return to START, the accumulator tested by BRP for 7 and 12, and the final HLT.
Record values only when they change. Record outputs in order and include the terminating state.
Use one row for each instruction carried out. Fill in a box only when that value changes on that row, and leave the rest blank. Put the address of the instruction being carried out in the Address column.
Inputs, in order: "7", "12", "0"
INP01BRZ END02SUB LIMIT03BRP HIGH04LDA LOWCODE05OUT06BRA START07HIGHLDA HIGHCODE08OUT09BRA START10ENDHLT11LIMITDAT 1012LOWCODEDAT 113HIGHCODEDAT 2| Row | Address | ACC | Output |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 | |||
| 8 | |||
| 9 | |||
| 10 | |||
| 11 | |||
| 12 | |||
| 13 | |||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | |||
| 18 |
After SUB LIMIT, the accumulator is zero. What does BRP LARGE do?
- ABranches to LARGE
- BContinues only for negative values
- CHalts
- DStores zero in LARGE
A programmer deletes the HLT immediately after the first OUT. Explain the exact fault for input 7 and state the repair.
Follow the next instruction after the first OUT. Count outputs and distinguish code from data.
Students type their answer here.
Apply the model independently
The remaining tasks change the context or reduce the support. Complete them without copying the worked model, then check that each explanation connects a mechanism to its consequence.
Amend the worked program so that input 10 is classified as small and only inputs greater than 10 produce 2. You may add a labelled instruction or change the comparison method. Explain why your route handles 9, 10 and 11 correctly.
BRP includes zero, so a simple unchanged branch is not sufficient. Show code and boundary reasoning.
Students type their answer here.
Write an LMC program that inputs two positive numbers, outputs their sum once, stores it in a labelled mailbox and halts.
Use primary Appendix mnemonics consistently. Put data after executable code.
Students type their answer here.
Review your understanding
Before submitting, check that you can explain the main distinction in your own words, apply it in an unfamiliar context and justify each consequence rather than only naming a feature.