Experiments described:
Indicates that interrupt-driven input and output can interrupt a running program, execute an interrupt service program, return the interrupted program, and continue execution from the next address in the interrupted location (as if nothing had happened).In the experiment, I used the keyboard as an input device to interrupt the running program.
A. User Programs
1. Your user program will contain ICS that continuously alternate vertically and horizontally, and output two different lines alternately, as follows:
ICS ICS ICS ICS ICS ICS
ICS ICS ICS ICS ICS
ICS ICS ICS ICS ICS ICS
ICS ICS ICS ICS ICS
ICS ICS ICS ICS ICS ICS
ICS ICS ICS ICS ICS
ICS ICS ICS ICS ICS ICS
ICS ICS ICS ICS ICS
2. Make sure your output is not too fast for the naked eye to notice.User programs should include counts between each line in small pieces of code, with intervals of countdown output from 2500 on the screen.
B. Keyboard interrupt service program
1. Keyboard interrupt service programs will simply write on the screen ten times, with the user randomly entering characters and ending with Enter (x0A).
2. Perhaps you do not use the TRAP command in your interrupt service program.If a character is displayed on the screen, you must detect the DSR register and write it into the DDR register, or you may not be able to call TRAP x21(OUT) or other TRAP programs.
C. Operating system supported code
1. Normally, the operating system will install some stack space first, so PC and PSR can be put on the stack when interrupts occur (as you know, when a program executes RTI, both PC and PSR will be ejected from the stack, and the processor will return to the program being interrupted). Since there is no operating system, initialize R6 to x3000 first, indicating an empty stack.
2. Normally, the operating system creates an interrupt vector table that contains the starting address of the corresponding interrupt service program. You must first create an interrupt vector table for keyboard interrupts.The starting address of the break vector table is x0100, and the break vector of the keyboard break is x80.You must provide an entry in the Interrupt Vector Table for this experiment.
Interrupt Drive I/O Diagram:
The interrupt-driven I/O execution process follows.In this experiment, if we enter a character on the keyboard, the I/O device requests service, and the priority is higher than that of the user program, the service will be interrupted until the end of the input carriage return (x000A).
User Program Flow Chart:
Interrupt Service Flow Chart:
Experimental results:
When a character is randomly entered, an interruption occurs, and the ICS is no longer looped until the Enter key is pressed.You can see that the input character is output 10 times (the red line part), and then the dead cycle continues.
Code implementation:
User Program lab4_ID_user_program
; The code is designed by Li Mingzhao. ; User program to print ICS checkerboard in an infinite loop. ; .ORIG x3000 ;initialize the stack pointer LD R6,STACK ;set up the keyboard interrupt vector table entry LD R1,INKB ; x0180 LD R2,ADDER ; x2000 STR R2,R1,#0 ;enable keyboard interrupts LD R3,IEE ; x4000. set 1 to the Interrupt Enable(14th bit) STI R3,KBSR ;start of actual user program to print ICS checkerboard REPUT LEA R0,ICS1 TRAP x22 ; output the string JSR DELAY LEA R0,ICS2 TRAP x22 ; output the string JSR DELAY BRnzp REPUT TRAP x25 ; delay output. DELAY ST R1,SaveR1 LD R1,COUNT ; #2500 REP ADD R1,R1,#-1 BRp REP LD R1,SaveR1 RET COUNT .FILL #25000 SaveR1 .BLKW 1 IEE .FILL x4000 STACK .FILL x3000 ADDER .FILL x2000 INKB .FILL x0180 ;INTV KBSR .FILL xFE00 ICS1 .STRINGZ "ICS ICS ICS ICS ICS ICS \n" ICS2 .STRINGZ " ICS ICS ICS ICS ICS ICS\n" .END
Interrupt service program lab4_interrupt_service_routine
; The code is desgined by Li Mingzhao. ; The interrupt service routine to output character you input 10 times. ; The interrupt service End with Enter(x000A). ; .ORIG x2000 ; Start at x2000 ADD R6,R6,#-1 ; Store the data at a stack. STR R0,R6,#0 ADD R6,R6,#-1 STR R1,R6,#0 ADD R6,R6,#-1 STR R2,R6,#0 ADD R6,R6,#-1 STR R3,R6,#0 LOOP ST R0,SaveR0 STAR LDI R1,KBSR ; Check the keyboard state. BRzp STAR LDI R0,KBDR LD R2,NEWLINE ; -x000A ADD R2,R2,R0 BRnp LOOP AND R3,R3,#0 ADD R3,R3,#10 AGAIN LD R0,SaveR0 START LDI R1,DSR ; Check the display state. BRzp START STI R0,DDR ADD R3,R3,#-1 BRp AGAIN LDR R3,R6,#0 ; Restore register. ADD R6,R6,#1 LDR R2,R6,#0 ADD R6,R6,#1 LDR R1,R6,#0 ADD R6,R6,#1 LDR R0,R6,#0 ADD R6,R6,#1 RTI ; Return to the user program. KBSR .FILL xFE00 KBDR .FILL xFE02 DSR .FILL xFE04 DDR .FILL xFE06 FIRST .FILL x4000 NEWLINE .FILL xFFF6 SaveR0 .FILL 0 .END