Control Flow and Branching

Learning Computer Architecture · 3:59

Listen on 93

Lyrics

[Verse 1]
In assembly language we take control
Jump instructions help us reach our goal
Unconditional jumps will always go
To the address that we choose to show
JMP takes us anywhere we need
No questions asked, it's guaranteed

[Chorus]
Branch and loop, decide and flow
Test the flags and then we know
Jump if zero, jump if not
Conditional logic hits the spot
CMP and TEST will set the way
For the branches we obey

[Verse 2]
Conditional branches check the state
Compare two values, then we wait
For the processor flags to tell us true
Is it equal, less, or greater too
JE jumps when values are the same
JNE continues the branching game

[Chorus]
Branch and loop, decide and flow
Test the flags and then we know
Jump if zero, jump if not
Conditional logic hits the spot
CMP and TEST will set the way
For the branches we obey

[Bridge]
Loops are branches that come back around
With counters keeping track of what we've found
While loops check the condition first
For loops count until the burst
Do-while loops will run at least one time
Making repetition so sublime

[Verse 3]
JL jumps when less than is the case
JG goes when greater shows its face
The carry flag and overflow
Tell us which direction we should go
Labels mark our destinations clear
The assembler keeps them always near

[Chorus]
Branch and loop, decide and flow
Test the flags and then we know
Jump if zero, jump if not
Conditional logic hits the spot
CMP and TEST will set the way
For the branches we obey

[Outro]
From simple jumps to complex trees
Control flow brings us to our knees
But master branches, loops, and more
You'll open up the coding door
Assembly logic, clean and bright
Makes every program work just right

← Basic Assembly Instructions | The Stack and Stack Operations →