In This Section
In This Section
In This Section
Introduction
A program is a set of instructions. We know that processor executes each instruction of
the program. A processor executes instructions one by one. Whatever we write in our
program is executed in the same order as it appears in the program.
Instructions are a set of commands stored in the computer's consecutive memory
locations.
These instructions are fetched from successive memory locations for processing and
executing. The change in the content of the program counter can cause a break in the
instruction execution. However, the program control instructions control the flow of
program execution and can branch to different program segments.
Most computer Instructions can be classified into three categories:
Data Transfer
Data Manipulation
Program Control Instructions
In this blog, we will have a look at Program Control Instructions.
Recommended Topic, 8085 Microprocessor Pin Diagram
What is Program Control Instructions?
Program control instructions modify or change the flow of a program. It is the instruction
that alters the sequence of the program's execution, which means it changes the value
of the program counter, due to which the execution of the program changes.
Features:
These instructions cause a change in the sequence of the execution of the
instruction.
This change can be through a condition or sometimes unconditional.
Flags represent the conditions.
Flag-Control Instructions.
Control Flow and the Jump Instructions include jumps, calls, returns, interrupts, and
machine control instructions.
Subroutine and Subroutine-Handling Instructions.
Loop and Loop-Handling Instructions.
Program
Control Description
Instructions
Branch which means it is an unconditional jump. It is unconditional
Branch (BR)
branching wherever we specify the address we need to branch.
Skip instructions is used to skip one(next) instruction. It can be conditional
or unconditional. It does not need an address field. In the case of
conditional skip instruction, the combination of conditional skip and an
Skip (SKP)
unconditional branch can be used as a replacement for the conditional
branch.
The jump instruction transfers the program sequence to the memory address
Jump (JMP) given in the operand based on the specified flag.
The Compare instruction performs a comparison via a subtraction, with
Compare
difference not retained. CMP compares register sized values, with one
(CMP)
exception.
The CALL and RETURN instructions interrupt the flow of a program by
passing control to an internal or external subroutine. An external subroutine
CALL and
is another program. The RETURN instruction returns control from a
RETURN
subroutine back to the calling program and optionally returns a value.
TEST instructions perform the AND of two operands without retaining the
TEST result, and so on.
Now let us move further, these all are unconditional jumps or unconditional branching,
which means there is no certain condition based on which they can jump or alter the
execution sequence.
Status Bit Conditions
To check different conditions for branching instructions like CMP (compare) or TEST
can be used. Certain status bit conditions are set as a result of these operations.
V Z S C
Status bits mean that the value will be either 0 or 1 as it is a bit. We have four status
bits:
"V" stands for Overflow
"Z" stands for Zero
"S" stands for the Sign bit
"C" stands for Carry.
Now, these will be set or reset based on the ALU (Arithmetic Logic Unit) operation
carried out into the CPU. Let us discuss these bits before understanding the operation.
Overflow(V) is based on certain bits, i.e., if extra bits are generated into our
operation. Then we have Zero (Z).
If the output of the ALU(Arithmetic Logic Unit) is 0, then the Z flag is set to 1,
otherwise, it is set to 0.
If the number is positive, the Sign(S) flag is 0, and if the number is negative, the
Sign flag is 1.
We have Carry(C), if the output of the thirst ALU operation generates Carry, then C
is set to 1, else C is set to 0.
Let's see how these flags are affected. You can see in the figure this is an 8-bit ALU that
performs arithmetic or logic operations on our data. Suppose we have two operands A
and B of 8-bits on which we are performing certain arithmetic or logic operations.
Arithmetic operation-addition is performed on A and B. We know that an extra Carry bit
may be generated, which means eight Carry bits are generated. If the addition operation
is performed on operands A and B, then the carry bits C0 to C7 may be generated. But
we know that extra Carry may also be generated, which we term as C8. If C8 is
generated, i.e., Carry is generated, reflecting our Carry flag, which results in the C flag
or C status bit being set to 1.
Let's move further to the last two carries, C7 and C8. If the XOR of these two carries
comes out to be 1, then we can say that the Overflow condition has happened and the
V flag is set to 1; otherwise, it's set to 0. This is the most occurring case when we have
negative numbers represented in 2's complement form.
Now moving on to the next flag which is the sign flag(S), the sign flag is set to 1 or 0
based on the output of the 8 bit ALU. As we know that if the number is positive, then the
most significant bit of a number is represented to be 0, which means if F7 is 0 then we
can say that the number is positive and if F7 is 1 then we say that the number is
negative.
And lastly, we have a Zero flag, Zero status bit Z, "Z" is said to 1 if the output of all the
bits from F0 to F7 is 0, then we can say that the zero flag is SET.
Now all these four bits that are "V", "Z", "S" and "C" are reflected based on the
arithmetic or logic operation carried out on the 8 bit ALU.
Also See, Shift Registers in Digital Electronics
Conditional Branch Instructions
A conditional branch instruction is basically used to examine the values that are stored
in the condition code register to examine whether the specific condition exists and to
branch if it does.
Conditional branch instructions such as ‘branch if zero’ or ‘branch if positive’ specify the
condition to transfer the execution flow. The branch address will be loaded in the
program counter when the condition is met.
Each conditional branch instruction tests for a different combination of Status bits for a
condition