Computer system (1) Experiment 5 interrupt experiment
Experimental purpose
Show how to make the input and output suspend and resume a running program by executing the interrupt handler. The restored program is like nothing happened in the middle. This experiment uses the keyboard as input to interrupt the running program.
Experiment contents and requirements
1. Write user program: the program outputs two different lines of "ICS" at continuous intervals
2. Write the keyboard interrupt processing program: the program simply prints the characters before the user's enter (x0A) 10 times at a time.
Write the operating system enabling code: initialize R6 to x3000, indicating an empty stack; Provide the address of the interrupt handler; Put IE position 1 of KBST
Experimental steps
1. Write the user program code according to the experimental requirements
(1) Enables the user program to output two different lines of "ICS" at continuous intervals
Figure 1 Two consecutive lines of different "ICS"
(2) Embedding the counting subroutine into the main program
Figure II subroutine
2. Write interrupt processing program according to the experimental requirements
Figure III Interrupt program code 1
Figure IV Interrupt program code 2
3. Write operating system enabling code
Initialize R6 to x3000, the starting address of the interrupt vector table is X0100, and the starting address of the keyboard interrupt handler is X80. Provide the address of the interrupt handler and set the IE position of KBSR to 1
Figure v Operating system enable code
4. Run code
Put the two sections of program code into LC3 simulator to run, enter a string of characters and press enter.
Figure VI The running state before the interrupt is not executed
Figure VII Enter the character "r" before carriage return
Figure VIII Enter the character "8" before carriage return
Program code and notes
Main program code: .ORIG x3000 ;The starting address of the interrupt vector table is X0100,The start address of the keyboard interrupt handler is X0180,hold x2000 Save to x0180 ;initialize the stack pointer ;set up the keyboard interrupt vector table entry LD R0,INTERRUPT LD R1,KEYBOARD STR R0,R1,#0 ;enable keyboard interrupts ;hold KBSR of IE(Interrupt Enable) Position 1, interrupt enable LD R0,KBSR1 LD R1,SETKBSRIE STR R1,R0,#0 LD R6,START ;Main program code ;start of actual user program to print ICS checkerboard OUTPUT LEA R0,ODD TRAP x22 LD R0,NEWLINE TRAP x21 JSR DELAY LEA R0,EVEN TRAP x22 JSR DELAY LD R0,NEWLINE TRAP x21 BRnzp OUTPUT STOP HALT ;Main program data area ODD .STRINGZ "ICS ICS ICS ICS ICS ICS" EVEN .STRINGZ " ICS ICS ICS ICS ICS" NEWLINE .FILL x000A START .FILL x3000 KEYBOARD .FILL x0180 INTERRUPT .FILL x2000 KBSR1 .FILL xFE00 SETKBSRIE .FILL x4000;And operation, extended to 16 bits ;Subroutine code DELAY ST R1,SAVER1 LD R1,COUNT REP ADD R1,R1,#-1 BRp REP LD R1,SAVER1 RET ;Subroutine data area COUNT .FILL #2500 SAVER1 .BLKW 1 .END Interrupt program code: .ORIG x2000 ;the code ;R2 Used to store output times ST R0,SAVER0 ST R1,SAVER1 ST R2,SAVER2 ST R3,SAVER3 ST R4,SAVER4 AND R2,R2,#0 ADD R2,R2,#10 ;Interrupt program code (by polling) INPUT LDI R3,KBSR BRzp INPUT LDI R0,KBDR OUTPUT LDI R3,DSR BRzp OUTPUT ;Determine whether it is enter AND R4,R4,#0 ADD R4,R4,#-10 ADD R4,R4,R0 BRz CIRCLE ST R0,LIN BRnzp INPUT ;Cycle output 10 times CIRCLE ADD R2,R2,#0 BRz STOP ADD R2,R2,#-1 LD R0,LIN STI R0,DDR BRnzp CIRCLE ; STOP LD R0,SAVER0 LD R1,SAVER1 LD R2,SAVER2 LD R3,SAVER3 LD R4,SAVER4 RTI HALT ;Interrupt program data area buffer space as required KBSR .FILL xFE00 KBDR .FILL xFE02 DSR .FILL xFE04 DDR .FILL xFE06 SAVER0 .BLKW 1 SAVER1 .BLKW 1 SAVER2 .BLKW 1 SAVER3 .BLKW 1 SAVER4 .BLKW 1 LIN .BLKW 1 .END
summary
I / O suspends and resumes a running program by executing an interrupt handler. The restored program is like nothing happened in the middle. The use of interrupt program can make the computer program more flexible.