All Exams Test series for 1 year @ ₹349 only
Question

In 8086, which instruction at the end of a sub-routine takes the execution back to the main program?

The correct answer is

RET

In the 8086 microprocessor, subroutines are an important way to organize code, promote reusability, and simplify complex programs. When a program executes a subroutine, it needs a specific instruction to return to the exact point in the main program from where the subroutine was called. This ensures the program flow continues seamlessly.

8086 Subroutine Execution

A subroutine, also known as a procedure, is a block of code that performs a specific task. It can be called multiple times from different parts of the main program or other subroutines. To manage the transfer of control, the 8086 uses a stack-based mechanism.

  • When a subroutine is invoked using the CALL instruction, the address of the instruction immediately following the CALL in the calling program (the return address) is automatically pushed onto the stack.
  • This return address is crucial because it tells the processor where to resume execution once the subroutine has completed its task.

RET Instruction Explained

The RET (Return) instruction is specifically designed to transfer execution control back from a subroutine to the calling program. It performs the following actions:

  • It retrieves the return address that was previously saved on the stack by the CALL instruction.
  • It then pops this return address from the stack into the Instruction Pointer (IP) register (and CS register for far calls).
  • Once the IP register holds the return address, the CPU fetches and executes the instruction located at that address, effectively continuing the execution of the main program from where it left off.

The RET instruction can also have an optional operand (e.g., RET N) which adds N bytes to the stack pointer (SP) after popping the return address. This is typically used to remove parameters pushed onto the stack by the calling program before the CALL.

Analyzing Other Instructions

Let's look at why the other options are not suitable for returning from a subroutine in 8086:

  • JMP (Jump): The JMP instruction is used for unconditional transfers of control to a specified address within the program. Unlike CALL and RET, JMP does not save any return address on the stack, nor does it pop any address from the stack. Therefore, using JMP at the end of a subroutine would lead to an incorrect program flow, as there would be no saved return address to go back to the original calling point.
  • END (End Directive): The END is an assembler directive, not an executable instruction for the 8086 microprocessor. It signals the end of the entire assembly source program to the assembler during the assembly process. It does not generate any machine code and thus cannot be executed by the processor to control program flow.
  • CALL (Call Subroutine): The CALL instruction is used to transfer control to a subroutine, not to return from one. As explained earlier, it saves the return address on the stack and then jumps to the subroutine's entry point. It is the instruction that initiates the subroutine execution, not terminates it in terms of returning control.

Conclusion on 8086 Return Instruction

Based on the functionality of the 8086 instructions, the instruction that takes the execution back to the main program at the end of a subroutine is RET. It correctly restores the program flow by retrieving the saved return address from the stack.

Was this answer helpful?

Important Questions from Microprocessors and Microcontrollers

  1. What is the total external data memory that can be interfaced to the 8051?

  2. Which one of the following is not the feature of 8051?

  3. What is the operation performed by the following assembly language program of 8051?

               CLR        A

                 MOV       R1, # 100H

                 MOV       R7, # 21H

    AGAIN: MOV      @ R1, A

                 INC         R1

                 DJNC      R7, AGAIN

  4. A stepper motor has the following specifications:

    Step angle: 2°

    Steps per revolution: 180

    No. of rotor teeth: 45

    Movement per 4-step sequence: 8°

    The following program will rotate a motor by how many degrees?

              ORG     0000H

                MOV     A, # 66H

                MOV     RO. #32

    BACK: RR        A

                MOV     PI, A

                ACALL  DELAY

                DJNZ    RO, BACK

                END

  5. Arrange the following activities to properly run the TYPE-4 Interrupt in 8086 micro processor:

    (A) Pushes the CS and IP value on stack for next instruction

    (B) Pushes the flag register on the stack

    (C) Reset TF and IF

    (D) Gets the CS value for start of interrupt service procedure

    Choose the correct answer from the options given below:

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App