6. Branching And Conditionals
In this section, we will focus on branching instructions. So far, you have seen instructions that execute sequentially; but many times, your program will need to execute code at a different memory address (like an if/else
statement, looping, functions, and so on). This is achieved by using branching instructions. Branching instructions transfer the control of execution to a different memory address. To perform branching, jump instructions are typically used in the assembly language. There are two kinds of jumps: conditional and unconditional.
6.1 Unconditional Jumps
In an unconditional jump, the jump is always taken. The jmp
instruction tells the CPU to execute code at a different memory address. This is similar to the goto
statement in the C programming language. When the following instruction is executed, the control is transferred to the jump address, and the execution starts from there:
jmp <jump address>
6.2 Conditional Jumps
In conditional jumps, the...