Concept Flow - Why branching controls program execution
Start
Check Condition
Yes|No
Branch Taken
Execute Branch
End
The program checks a condition, then decides to branch (jump) or continue sequentially, controlling which instructions run next.
CMP R0, #0 BEQ label MOV R1, #1 label: MOV R1, #2
| Step | Instruction | Condition | Branch Taken? | Action | R1 Value |
|---|---|---|---|---|---|
| 1 | CMP R0, #0 | R0 == 0? | N/A | Compare R0 with 0 | Undefined |
| 2 | BEQ label | R0 == 0? | Yes if R0=0 | Jump to label if equal | Undefined |
| 3 | MOV R1, #1 | N/A | No if branch taken | Set R1 to 1 | 1 |
| 4 | label: MOV R1, #2 | N/A | Executed if branch taken or after MOV R1=1 | Set R1 to 2 | 2 |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | After Step 4 |
|---|---|---|---|---|---|
| R0 | Input value | Input value | Input value | Input value | Input value |
| R1 | Undefined | Undefined | Undefined or skipped | 1 or skipped | 2 |
Branching lets a program choose different paths based on conditions. A condition is checked (like comparing a register). If true, the program jumps to a new instruction (branch). If false, it continues in order. This controls which instructions run next.