.data msg: .asciiz "\nGot an interrupt." .text .globl main main: # enable interrupts on the CPU. mfc0 $t0, $12 ori $t0, $t0, 0x1 mtc0 $t0, $12 # enable interrupts on the keyboard and console device li $t0, 0xffff0000 # address of receiver control li $v0, 0x2 sw $v0, 0($t0) sw $v0, 8($t0) forever: addi $s0, $s0, 1 # do some real work j forever jr $ra ################## I N T E R R U P T H A N D L E R ####################### .ktext 0x80000180 # This is an interrupt handler user to echo the # keyboard input to the console. interrupt_handler: # determine the cause of the interrupt mfc0 $k0, $13 # get the cause register srl $a0, $k0, 2 # get the exception code andi $a0, $a0, 0x1f # bits 2-6 of cause bne $a0, $zero, done # if it is not an interrupt we're done # see if keyboard caused interrupt li $t0, 0xffff0000 lw $v0, 0($t0) # get receiver control andi $v0, $v0, 0x01 # get ready bit beq $v0, $zero, done # wait until ready to write write_poll: lw $v0, 8($t0) andi $v0, $v0, 0x1 beq $v0, $zero, write_poll # read character from keyboard and # write to console lw $v0, 4($t0) sw $v0, 12($t0) done: mtc0 $0 $13 # Clear Cause register mfc0 $k0 $12 # Set Status register ori $k0 0x1 # Interrupts enabled mtc0 $k0 $12 eret .text .globl __start __start: jal main li $v0 10 syscall # syscall 10 (exit)