#########################################################################
#									#
#		Goodman's kernel for assignment 11.		        #
#									#
#	This kernel is simpler than the original kernel. 	        #
#	You are welcome to use it if you prefer it.		        #
#	Your code should be put at the end of this file.		#
#	You should leave the first instruction (mtc0)			#
#	where it is -- it prevents jumping to the kernel		#
#	because of interrupts.						#
#									#
#########################################################################

	    # The ".eq" instruction is used to assign an fixed
	    # address to a label.  So "lw $t0, KeyboardStatus" loads
	    # a word from memory at adderss 0xbfff0004 into
	    # register t0.

    	# Assign addresses to labels.
	.eq	KeyboardData	0xbfff0000
	.eq	KeyboardStatus	0xbfff0004
	.eq	DisplayData	0xbfff0008
	.eq	DisplayStatus	0xbfff000c

	.kdata
tmpra:  .word	0	# Temporary storage for register 31

     #
     # other temporary register storage would be setup here...
     #

	.ktext
	.space	0x80	# Skip space so kernel starts at 0x80000080

Service:
			#Save needed registers
	sw	$ra, tmpra

     #
     # other registers would be saved here...
     #


HandleSys:

	beq	$v0, 10, Exit	# Is it exit?

     #
     # other tests for syscalls would go here...
     #

	j	Return		# Unknown syscall; do nothing and return


				#Code to handle return to user code.
Return:	lw	$ra, tmpra	# Restore saved registers

     #
     # other registers would be restored here...
     #

	mfc0	$k0, $14	# Get the EPC register
	add	$k0, $k0, 4	# Skip syscall instruction
	jr	$k0


# Exit routine - exits the program, by stopping the simulator
# In a real computer there is no way to stop running.
# If this was UNIX we could now run someone elses program.
# Since this is a simulater, we call a special syscall
# that never returns, becuase it causes the simulator to stop.

Exit:	li	$v0, 13
	syscall		# This call does not return

     #
     # other tests for syscalls would go here...
     #


	.text
	.globl __start
#########################################################################
#        								#
#        		End of kernel					#
#        								#
#########################################################################

	.text
__start:    # Tell spim where to start execution
	    # Initialization code to turn off all interrupts:
         mtc0        $0, $12

	<your code here>


