Instructions
Objective
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.
Main Program
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






Source Code
; 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] <- x2600
	LD R6,STACK
	LD R0, KBISR ; 2600
	LD R1, KBINTVec ; x0180
	STR R0, R1, #0
	; enable keyboard interrupts
	; KBSR[14] <- 1 ==== M[xFE00] = x4000
	LD R0, KBINTEN
	STI R0, KBSR
	AND R1, R1, #0 ; start in state 0
	; This loop is the proper way to read an input
	Loop
	LDI R0,GLOB
	BRz Loop  
	; Process it
	TRAP x21 ; echo character read
	ADD R2, R1, #0 ; if state is zero
	BRz ST0 ; go to state zero
	ADD R2, R1, #-1 ; if state is 1
	BRz ST1 ; go to state 1
	ADD R2, R1, #-2 ; if state is 2
	BRz ST2 ; go to state 2
	ADD R2, R1, #-3 ; if state is 3
	BRz ST3 ; go to state 3
	ADD R2, R1, #-4 ; if state is 4
	BRz ST4 ; go to state 4
	ADD R2, R1, #-5 ; if state is 5
	BRz ST5 ; go to state 5
	ADD R2, R1, #-6 ; if state is 6
	BRz ST6 ; go to state 6
	ADD R2, R1, #-7 ; if state is 7
	BRz ST7 ; go to state 7
	ST0
	LD R2, ANEG
	ADD R0, R0, R2 ; compare with 'A'
	BRnp CLEAR ; if != 'A', clear and restart
	ADD R1, R1, #1 ; else jump to state 1
	BRnzp CLEAR ; clear and restart
	ST1
	LD R2, UNEG
	ADD R0, R0, R2 ; compare with 'U'
	BRz NXT2 ; if = 'U', go to next
	AND R1, R1, #0 ; else, reset state to 0
	BRnzp CLEAR ; clear and restart
	NXT2
	ADD R1, R0, #2 ; jump to state 2
	BRnzp CLEAR ; clear and restart
	ST2
	LD R2, GNEG
	ADD R0, R0, R2 ; compare with 'G'
	BRz NXT3 ; if = 'G', go to next
	AND R1, R1, #0 ; else, reset state to 0
	BRnzp CLEAR ; clear and restart
	NXT3
	ADD R1, R0, #3 ; jump to state 3
	LD R0, PIPE ; load pipe symbol
	TRAP x21 ; print pipe
	BRnzp CLEAR ; clear and restart
	ST3
	LD R2, UNEG
	ADD R0, R0, R2 ; compare with 'U'
	BRz NXT5 ; if = 'U', go to next
	ADD R1, R1, #1 ; else, go to state 4
	BRnzp CLEAR ; clear and restart
	NXT5
	ADD R1, R0, #5 ; jump to state 5
	BRnzp CLEAR ; clear and restart
	ST4
	LD R2, UNEG
	ADD R0, R0, R2 ; compare with 'U'
	BRz NXT5 ; if = 'U', go to state 5
	BRnzp CLEAR ; else, clear and restart
	ST5
	LD R2, ANEG
	ADD R0, R0, R2 ; compare with 'A'
	BRz NXT6 ; if = 'A', go to state 6
	ADD R0, R0, #-2 ; compare with 'C'
	BRz NXT4 ; if = 'C', go to state 4
	ADD R0, R0, #-4 ; compare with 'G'
	BRz NXT7 ; if = 'G', go to state 7
	BRnzp CLEAR ; else, stay in 5
	NXT4
	ADD R1, R0, #4 ; jump to state 4
	BRnzp CLEAR ; clear and restart
	NXT6
	ADD R1, R0, #6 ; jump to state 6
	BRnzp CLEAR ; clear and restart
	NXT7
	ADD R1, R0, #7 ; jump to state 7
	BRnzp CLEAR ; clear and restart
	ST6
	LD R2, ANEG
	ADD R0, R0, R2 ; compare with 'A'
	BRz STOP ; if = 'A', terminate
	ADD R0, R0, #-2 ; compare with 'C'
	BRz NXT4 ; if = 'C', go to state 4
	ADD R0, R0, #-4 ; compare with 'G'
	BRz STOP ; if = 'G', terminate
	AND R0, R0, #0
	BRnzp NXT5 ; else, go to 5
	ST7
	LD R2, ANEG
	ADD R0, R0, R2 ; compare with 'A'
	BRz STOP ; if = 'A', terminate
	ADD R0, R0, #-2 ; compare with 'C'
	BRz NXT4 ; if = 'C', go to state 4
	ADD R0, R0, #-4 ; compare with 'G'
	BRz NXT4 ; if = 'G', go to state 4
	AND R0, R0, #0
	BRnzp NXT5 ; else, go to 5
	CLEAR
	AND R0, R0, #0 ; load zero
	STI R0, GLOB ; save 0 to wait for another char
	BRnzp Loop ; repeat loop  
	; Repeat unil Stop Codon detected
	STOP
	HALT
	KBINTVec .FILL x0180
	KBSR .FILL xFE00
	KBISR .FILL x2600
	KBINTEN .FILL x4000
	GLOB .FILL x3600
	ANEG .FILL x-41
	CNEG .FILL x-43
	GNEG .FILL x-47
	UNEG .FILL x-55
	PIPE .FILL x7C
	STACK .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 x2600
	ST R0, OLDR0 ; save R0
	ST R1, OLDR1 ; save R1
	LDI R0, KBDR ; load character
	LD R1, ANEGISR ; load -A
	ADD R1, R1, R0 ; compare with 'A'
	BRz SAVE ; if = 'A', save
	LD R1, CNEGISR ; load -C
	ADD R1, R1, R0 ; compare with 'C'
	BRz SAVE ; if = 'C', save
	LD R1, GNEGISR ; load -G
	ADD R1, R1, R0 ; compare with 'G'
	BRz SAVE ; if = 'G', save
	LD R1, UNEGISR ; load -U
	ADD R1, R1, R0 ; compare with 'U'
	BRnp ISRDONE ; if != 'U', don't save
	SAVE
	STI R0, GLOB ; save char in global
	ISRDONE
	LD R0, OLDR0 ; restore R0
	LD R1, OLDR1 ; restore R1
	RTI
	OLDR0 .FILL x0
	OLDR1 .FILL x0
	KBDR .FILL xFE02
	GLOB .FILL x3600
	ANEGISR .FILL x-41
	CNEGISR .FILL x-43
	GNEGISR .FILL x-47
	UNEGISR .FILL x-55
	.END 
Related Samples
Explore our collection of free assembly language assignment samples. These resources offer valuable insights and examples to help you grasp key concepts and excel in your studies. Access them now to enhance your understanding and academic performance.
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
Assembly Language
