# Test interrupt-driven i/o. .text main: addi $sp,$sp,-4 sw $s0,0($sp) la $t7,enableInterrupts jalr $t7 la $s0,alphabet loop1: lb $a0,0($s0) beq $a0,$0,loop1done la $t7,putchar jalr $t7 addi $s0,$s0,1 j loop1 loop1done: add $s0,$0,$0 loop2: la $t7,getchar jalr $t7 add $a0,$v0,$0 la $t7,putchar jalr $t7 addi $s0,$s0,1 j loop2 .data alphabet: .asciiz "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" .ktext enableInterrupts: mfc0 $t0,$12 # Record interrupt state by saving Status register. andi $t0,$t0,0xFFFE # Clear interrupt enable flag. mtc0 $t0,$12 # Turn interrupts off. lui $t0,0xFFFF lw $t1,0($t0) # Read receiver (keyboard) control word. ori $t1,$t1,2 # Set receiver interrupt-enable. sw $t1,0($t0) mfc0 $t0,$12 # Record interrupt state. ori $t0,$t0,0xFF01 # Set global interrupt-enable flags. mtc0 $t0,$12 # Turn interrupts on lui $t0,0xFFFF sw $0,12($t0) # Send a null character to the transmitter. jr $ra getchar: lb $t0,inputBufferIsFull beq $t0,$0,getchar # No character is waiting, so just wait for user to type something. lb $v0,inputBuffer # Remove character from the buffer and return it. sb $0,inputBufferIsFull jr $ra putchar: sb $a0,outputBuffer # Store character into the output buffer. addi $t3,$0,1 sb $t3,outputBufferIsFull lui $t0,0xFFFF # Turn on transmitter (display) interrupts. lw $t1,8($t0) ori $t1,$t1,2 sw $t1,8($t0) jr $ra