Open In App

Types of Program Control Instructions

Last Updated : 27 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In microprocessor and Microcontroller ,program control instructions guide how a computer executes a program by allowing changes in the normal flow of operations. These instructions help in making decisions, repeating tasks, or stopping the program.

What is Program Control Instructions ?

Program Control Instructions are the machine code instructions which are used to control the flow of execution of instructions in the processor domain. These are important in instilling on the processor how to execute a certain task, access different programs and control the decision making on the basis of some conditions. They are commonly used in assembly language and generated by high level language which is compiled into machine code form to enable the processor act in the desired manner.

Types of Program Control Instructions

1. Compare Instruction

Compare instruction is specifically provided, which is similar to a subtract instruction except the result is not stored anywhere, but flags are set according to the result. 

Example: CMP R1, R2 ;

2. Unconditional Branch Instruction

It causes an unconditional change of execution sequence to a new location. 

Example: JUMP L2 Mov R3, R1 goto L2

3. Conditional Branch Instruction

A conditional branch instruction is used to examine the values stored in the condition code register to determine whether the specific condition exists and to branch if it does. 

Example: Assembly Code : BE R1, R2, L1 Compiler allocates R1 for x and R2 for y High Level Code: if (x==y) goto L1;

4. Subroutines

A subroutine is a program fragment that lives in user space, performs a well-defined task. It is invoked by another user program and returns control to the calling program when finished. 

Example: CALL and RET

5. Halting Instructions

  • NOP Instruction - NOP is no operation. It cause no change in the processor state other than an advancement of the program counter. It can be used to synchronize timing. 
     
  • HALT - It brings the processor to an orderly halt, remaining in an idle state until restarted by interrupt, trace, reset or external action.  

6. Interrupt Instructions

Interrupt is a mechanism by which an I/O or an instruction can suspend the normal execution of processor and get itself serviced. 

  • RESET - It reset the processor. This may include any or all setting registers to an initial value or setting program counter to standard starting location.
  • TRAP - It is non-maskable edge and level triggered interrupt. TRAP has the highest priority and vectored interrupt.
  • INTR - It is level triggered and maskable interrupt. It has the lowest priority. It can be disabled by resetting the processor.

Advantages of Program Control Instructions

  • Efficient Control Flow: Program Control Instructions provide the processor with the means to decide the order of instructions. This means that branching can be efficiently made which is important for complicated mathematics as well as algorithms.
  • Conditional Execution: With conditional instruction, code can be executed whenever a specific condition is met thereby improving the usability of programs in dealing with different situations.
  • Modular Code: Modular are especially subroutines where separate code can be carried, simplifying its usage as most calls basically involve performing standard functionalities as and when required.
  • Synchronization: Instructions such as NOP and HALT helps in the militia of processes as well for any inoperable phase Of the system thereby protects it from unnecessary algorithm.
  • Interrupt Handling: Interrupt strategies give real time competencies since they give the processor the ability to attend to peripheral devices and other kinds of processes promptly.
  • Efficient Resource Management: These instructions encumber improvement in resource management over system operations by stopping, resuming or terminating them when high performance is needed by the CPU.

Disadvantages of Program Control Instructions

  • Complexity: In cases of program control instructions, mainly regarding assembly language, it can be complicated to write and understand such instructions as they require thorough understanding of the way a processor is designed.
  • Performance Overhead: The use of conditional controls and subroutine calls has its drawbacks where branching and moving back to previous statuses especially when they contain nested calls or excessive use can be performance hindrances.
  • Risk of Errors: Identifying errors such as the program branching where it is not supposed to or the abuse of interrupts can lead to errors such as program hanging where the program goes into loops and does not progress any further rendering fixing it virtually impossible.
  • Dependency on Processor Architecture: These type of instructions are very particular with the processor architecture to an extent that such type of software cannot be run on a different hardware platform.
  • Interrupt Latency: This is on handling interrupts has some downsides particularly latency if there is a need to handle several interrupts of different priorities.
  • Overhead with Subroutines: There is little doubt that the use of subroutine physically changes the way the code is organized and though it saves time concerning the code, too many transitions between the code and the subroutine/main program usually wastes time within the detractors of the stack management.

Conclusion

PCI is crucial for synchronizing the execution of the programs in a processor because it provides the sections of code for the management of the flow. They permit branching, decision, and proper management of tasks in the most successful manner possible. These instructions also assist an assembly level programmer and aid in the analysis of how high level language is compiled and translated into machine instructions for execution by the processor.


Next Article

Similar Reads