Presentation is loading. Please wait.

Presentation is loading. Please wait.

10-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL 62901 Subroutine and Interrupt.

Similar presentations


Presentation on theme: "10-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL 62901 Subroutine and Interrupt."— Presentation transcript:

1 10-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL 62901 Subroutine and Interrupt Instructions

2 10-2 Subroutine Instructions  A subroutine is a collection of instructions that can be called from one or more other locations within a program  CALL Procedure-Name MOV AL, 1 CALL M1 MOV BL, 3 M PROC MOV CL, 2 RET M ENDP — Example The order of execution: MOV AL, 1 MOV CL, 2 MOV BL, 3 — Intersegment CALL: the subroutine is located in a different code segment — Intrasegment CALL: the subroutine is located in the same code segment — Use assembler directives far and near to distinguish intersegment and intrasegment CALL

3 10-3 Subroutine Instructions  What does the microprocessor do when it encounters a CALL instruction? 1.Push the values of CS and IP (which specify the address of the instruction immediately following the CALL instruction) into stack. If it is a intrasegment CALL, just push the value of IP into stack. 2.Load the new values to CS and IP such that the next instruction that the microprocessor will fetch is the first instruction of the subroutine.model small 0000.code 0000 B0 02MOV AL, 2 0002 E8 0002CALL m1 0005 B3 03MOV BL, 3 0007 m1 Proc 0007 B7 05MOV BH, 5 0009 C3RET 000A m1 ENDP end — Example: 12345H Stack before CALL What are in the stack after the execution of CALL? How about if the CALL is an intersegment CALL? 11

4 10-4 Subroutine Instructions  RET — It lets the microprocessor exit from a subroutine — If it is used in a FAR procedure, RET pops two words from the stack. The first one goes to IP register. The second one goes to CS register — If it is used in a NEAR procedure, RET pops one word from stack to IP register 1234:2345 1234:2348 CALL FAR PTR M1 1234:234D M1 PROC FAR 3456:0120 MOV AL, 0 RET M1 ENDP — Example: 01022 What data are pushed into and popped from the stack during the execution of CALL and RET?

5 10-5.model small 0000.code 0000 B0 00 MOV AL, 0 0002 9A ---- 000A R CALL far ptr M1 0007 B0 00 MOV AL, 0 0009 C3 RET 000A M1 PROC Far 000A B3 01 MOV BL, 1 000C CB RET 000D M1 ENDP END.model small 0000.code 0000 B0 00MOV AL, 0 0002 E8 0003CALL M1 0005 B0 00MOV AL, 0 0007 C3RET 0008 M1 PROC 0008 B3 01MOV BL, 1 000A C3RET 000B M1 ENDP END Subroutine Instructions  Different machine codes are used to call and return from NEAR or FAR subroutines  NEAR subroutine  FAR subroutine

6 10-6 Interrupt Instructions  INT Interrupt-Type — This instruction causes the microprocessor to execute an interrupt service routine. The Interrupt-Type is an immediate data (0-255) which specifies the type of interrupt — It results in the following operations: 1.Push flag register into stack 2.Clear trace flag and interrupt-enable flag 3.Push CS and IP into stack 4.Load new CS and IP values from the interrupt vector table — Example: 1230:6789 INT 20H After the execution of INT 20H, what are the data pushed into the stack? EA62345H

7 10-7 Interrupt Instructions  IRET — It is used at the end of an interrupt service routine to make the microprocessor jump back to the instruction that immediately follows the INT instruction INT 20H MOV AL, 0 Interrupt service routine MOV, AL, 0 IRET — It results in the following operations 1.Restore the original CS and IP values by popping them from stack 2.Restore the original flag register value by popping it from stack  INTO — If OF=1, it results in a type-4 interrupt


Download ppt "10-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL 62901 Subroutine and Interrupt."

Similar presentations


Ads by Google