0
0
ARM Architectureknowledge~10 mins

Branch instruction (B) in ARM Architecture - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Branch instruction (B)
Start Execution
Fetch Branch Instruction
Decode Instruction
Calculate Target Address
Update Program Counter (PC)
Jump to Target Address
Continue Execution from New Address
The branch instruction changes the flow by updating the program counter to a new address, causing the CPU to jump to that location.
Execution Sample
ARM Architecture
B label
...
label:
  MOV R0, #1
This code jumps to 'label' skipping intermediate instructions, then sets register R0 to 1.
Analysis Table
StepInstructionProgram Counter (PC)ActionNext PC
1B label0x1000Calculate target address for 'label'0x1008
2B label0x1000Update PC to target address0x1008
3MOV R0, #10x1008Execute MOV instruction0x100C
4...0x100CContinue sequential execution0x1010
💡 Execution continues from updated PC after branch; branch instruction changes flow to 0x1008
State Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4
PC0x10000x10000x10080x100C0x1010
R0undefinedundefinedundefined11
Key Insights - 2 Insights
Why does the program counter (PC) jump to 0x1008 instead of continuing sequentially?
Because the branch instruction (B) updates the PC to the target address (0x1008), changing the flow as shown in execution_table rows 1 and 2.
Does the branch instruction execute the instructions between 0x1000 and 0x1008?
No, the branch skips intermediate instructions by directly updating PC to 0x1008, so instructions between are not executed (see execution_table step 2).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2. What is the value of PC after executing the branch instruction?
A0x1008
B0x1000
C0x100C
D0x1010
💡 Hint
Check the 'Next PC' column in execution_table row 2.
At which step does register R0 get the value 1?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Action' column where MOV R0, #1 is executed.
If the branch instruction was removed, what would happen to the PC after step 1?
APC would update to 0x1008
BPC would continue sequentially to 0x1004
CPC would jump to 0x1010
DPC would stay at 0x1000
💡 Hint
Without branch, PC increments sequentially; check variable_tracker for PC values.
Concept Snapshot
Branch instruction (B) changes program flow by updating the PC to a target address.
Syntax: B label
It causes the CPU to jump, skipping instructions in between.
Used for loops, conditionals, and function calls.
PC updates immediately to target address after branch.
Full Transcript
The branch instruction (B) in ARM architecture changes the flow of execution by updating the program counter (PC) to a new address. When the CPU encounters a branch instruction, it calculates the target address and sets the PC to that address, causing the next instruction to be fetched from there. This skips any instructions between the branch and the target. For example, if the PC is at 0x1000 and the branch target is 0x1008, the PC jumps directly to 0x1008. This is shown in the execution table where after executing the branch, the PC updates from 0x1000 to 0x1008. The branch is useful for implementing loops, conditionals, and jumps in code. Registers like R0 remain unchanged until instructions at the target address execute, such as MOV R0, #1 at 0x1008. Understanding how the PC updates helps clarify how the CPU changes execution flow with branch instructions.