1 / 7

ECE 424 Design of Microprocessor-Based Systems

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

yair
Download Presentation

ECE 424 Design of Microprocessor-Based Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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 • Example • • • MOV AL, 1 CALL M1 MOV BL, 3 • • • M PROC MOV CL, 2 RET M ENDP 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. Subroutine Instructions • What does the microprocessor do when it encounters a CALL instruction? • Push the values of CS and IP (which specify the address of the instruction immediatelyfollowing the CALL instruction) into stack. If it is a intrasegment CALL, just push the value of IP into stack. • 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 • Example: .model small 0000 .code 0000 B0 02 MOV AL, 2 0002 E8 0002 CALL m1 0005 B3 03 MOV BL, 3 0007 m1 Proc 0007 B7 05 MOV BH, 5 0009 C3 RET 000A m1 ENDP end What are in the stackafter the execution of CALL? How about if the CALL is an intersegment CALL? Stack before CALL 12345H 11

  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 • Example: 1234:2345 ••• 1234:2348 CALL FAR PTR M1 1234:234D ••• M1 PROC FAR 3456:0120 MOV AL, 0 ••• RET M1 ENDP What data are pushed into and popped from the stack during the execution of CALL and RET? 01022

  5. Subroutine Instructions • Different machine codes are used to call and return from NEAR or FAR subroutines • NEAR subroutine • FAR subroutine .model small 0000 .code 0000 B0 00 MOV AL, 0 0002 E8 0003 CALL M1 0005 B0 00 MOV AL, 0 0007 C3 RET 0008 M1 PROC 0008 B3 01 MOV BL, 1 000A C3 RET 000B M1 ENDP END .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

  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: • Push flag register into stack • Clear trace flag and interrupt-enable flag • Push CS and IP into stack • Load new CS and IP values from the interrupt vector table • Example: ••• 1230:6789 INT 20H ••• 62345H EA After the execution of INT 20H, what are the data pushed into the stack?

  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 • Restore the original CS and IP values by popping them from stack • Restore the original flag register value by popping it from stack • INTO • If OF=1, it results in a type-4 interrupt

More Related