Write a program in LC3 assembly language to enter text using interrupt handler.
Requirements and Specifications
Interrupt Service Routine (ISR)
In this assignment, we will use the keyboard as the input device for interrupting the main program. The ISR will start at x2600. The ISR simply reads the character typed and accepts only the symbols ‘A’, ‘C’, ‘G’, or ‘U’. Any other symbol will be ignored. Once it detects a valid symbol, it places it at location x3600.
Note, any value other than 0 at this location indicates a valid input character as the ISR only writes valid characters. Also, the ISR does not echo the character to the console. It is considered bad programming to perform time-consuming tasks like I/O inside Interrupt Service Routines.
The main program will constantly check the location x3600 to see if there is an input character there and writes a 0to the location when it processes it. Processing an input character follows a simple algorithm which can be described by the above incomplete finite state machine (FSM). It is incomplete in that, it does not account for all inputs in all states but only presents some of the relevant inputs. You are welcome to solve the problem without the FSM as long as you implement the expected functionality. The Main program will start at x3000and will write to the screen the character it reads from x3600 , making sure it does this only once for each input entered. Also, it checks to see if a START codon (AUG) is detected. If so, it prints the pipe symbol ‘|’. After this point, it looks for a STOP codon (UAG, UAA, or UGA) so the program can terminate. (Note that for this program, the coding sequence itself does not need to be aligned in groups of 3 bases per codon. This is unlike real mRNA.)
VERY IMPORTANT: You are not allowed to use any TRAP instructions in your interrupt service routine.
To read a character that the user entered, you may not call TRAP x20(GETC) or TRAP x23(IN), or use any of the other TRAP routines. If you use TRAP in the interrupt service, your program is not correct and will fail our testing even though it may appear to work when you test it. You are free to use TRAPs in themain program. Do not forget to save and restore any registers that you use in the interrupt serviceroutine.
Screenshots of output
; Program5.asm; Name(s):; UTEid(s):; Continuously reads from x3600 making sure its not reading duplicate; symbols. Processes the symbol based on the program description; of mRNA processing..ORIG x3000; set up the keyboard interrupt vector table entry;M[x0180] <- x2600LD R6,STACKLD R0, KBISR ; 2600LD R1, KBINTVec ; x0180STR R0, R1, #0; enable keyboard interrupts; KBSR <- 1 ==== M[xFE00] = x4000LD R0, KBINTENSTI R0, KBSRAND R1, R1, #0 ; start in state 0; This loop is the proper way to read an inputLoopLDI R0,GLOBBRz Loop; Process itTRAP x21 ; echo character readADD R2, R1, #0 ; if state is zeroBRz ST0 ; go to state zeroADD R2, R1, #-1 ; if state is 1BRz ST1 ; go to state 1ADD R2, R1, #-2 ; if state is 2BRz ST2 ; go to state 2ADD R2, R1, #-3 ; if state is 3BRz ST3 ; go to state 3ADD R2, R1, #-4 ; if state is 4BRz ST4 ; go to state 4ADD R2, R1, #-5 ; if state is 5BRz ST5 ; go to state 5ADD R2, R1, #-6 ; if state is 6BRz ST6 ; go to state 6ADD R2, R1, #-7 ; if state is 7BRz ST7 ; go to state 7ST0LD R2, ANEGADD R0, R0, R2 ; compare with 'A'BRnp CLEAR ; if != 'A', clear and restartADD R1, R1, #1 ; else jump to state 1BRnzp CLEAR ; clear and restartST1LD R2, UNEGADD R0, R0, R2 ; compare with 'U'BRz NXT2 ; if = 'U', go to nextAND R1, R1, #0 ; else, reset state to 0BRnzp CLEAR ; clear and restartNXT2ADD R1, R0, #2 ; jump to state 2BRnzp CLEAR ; clear and restartST2LD R2, GNEGADD R0, R0, R2 ; compare with 'G'BRz NXT3 ; if = 'G', go to nextAND R1, R1, #0 ; else, reset state to 0BRnzp CLEAR ; clear and restartNXT3ADD R1, R0, #3 ; jump to state 3LD R0, PIPE ; load pipe symbolTRAP x21 ; print pipeBRnzp CLEAR ; clear and restartST3LD R2, UNEGADD R0, R0, R2 ; compare with 'U'BRz NXT5 ; if = 'U', go to nextADD R1, R1, #1 ; else, go to state 4BRnzp CLEAR ; clear and restartNXT5ADD R1, R0, #5 ; jump to state 5BRnzp CLEAR ; clear and restartST4LD R2, UNEGADD R0, R0, R2 ; compare with 'U'BRz NXT5 ; if = 'U', go to state 5BRnzp CLEAR ; else, clear and restartST5LD R2, ANEGADD R0, R0, R2 ; compare with 'A'BRz NXT6 ; if = 'A', go to state 6ADD R0, R0, #-2 ; compare with 'C'BRz NXT4 ; if = 'C', go to state 4ADD R0, R0, #-4 ; compare with 'G'BRz NXT7 ; if = 'G', go to state 7BRnzp CLEAR ; else, stay in 5NXT4ADD R1, R0, #4 ; jump to state 4BRnzp CLEAR ; clear and restartNXT6ADD R1, R0, #6 ; jump to state 6BRnzp CLEAR ; clear and restartNXT7ADD R1, R0, #7 ; jump to state 7BRnzp CLEAR ; clear and restartST6LD R2, ANEGADD R0, R0, R2 ; compare with 'A'BRz STOP ; if = 'A', terminateADD R0, R0, #-2 ; compare with 'C'BRz NXT4 ; if = 'C', go to state 4ADD R0, R0, #-4 ; compare with 'G'BRz STOP ; if = 'G', terminateAND R0, R0, #0BRnzp NXT5 ; else, go to 5ST7LD R2, ANEGADD R0, R0, R2 ; compare with 'A'BRz STOP ; if = 'A', terminateADD R0, R0, #-2 ; compare with 'C'BRz NXT4 ; if = 'C', go to state 4ADD R0, R0, #-4 ; compare with 'G'BRz NXT4 ; if = 'G', go to state 4AND R0, R0, #0BRnzp NXT5 ; else, go to 5CLEARAND R0, R0, #0 ; load zeroSTI R0, GLOB ; save 0 to wait for another charBRnzp Loop ; repeat loop; Repeat unil Stop Codon detectedSTOPHALTKBINTVec .FILL x0180KBSR .FILL xFE00KBISR .FILL x2600KBINTEN .FILL x4000GLOB .FILL x3600ANEG .FILL x-41CNEG .FILL x-43GNEG .FILL x-47UNEG .FILL x-55PIPE .FILL x7CSTACK .FILL x3000.END; Interrupt Service Routine; Keyboard ISR runs when a key is struck; Checks for a valid RNA symbol and places it at x3600.ORIG x2600ST R0, OLDR0 ; save R0ST R1, OLDR1 ; save R1LDI R0, KBDR ; load characterLD R1, ANEGISR ; load -AADD R1, R1, R0 ; compare with 'A'BRz SAVE ; if = 'A', saveLD R1, CNEGISR ; load -CADD R1, R1, R0 ; compare with 'C'BRz SAVE ; if = 'C', saveLD R1, GNEGISR ; load -GADD R1, R1, R0 ; compare with 'G'BRz SAVE ; if = 'G', saveLD R1, UNEGISR ; load -UADD R1, R1, R0 ; compare with 'U'BRnp ISRDONE ; if != 'U', don't saveSAVESTI R0, GLOB ; save char in globalISRDONELD R0, OLDR0 ; restore R0LD R1, OLDR1 ; restore R1RTIOLDR0 .FILL x0OLDR1 .FILL x0KBDR .FILL xFE02GLOB .FILL x3600ANEGISR .FILL x-41CNEGISR .FILL x-43GNEGISR .FILL x-47UNEGISR .FILL x-55.END