# example code to enable interrupts # spim -mapped_io -noexception # load "buffer.s" # load "program.8b" .data buffer: .space 65 msg: .asciiz "\n Elapsed Time = " nl: .asciiz "\n" .text main: la $s3 buffer # buffer address li $s4 64 # buffer size or $s0 $0 $0 # current offset in buffer ori $t1 $0 0xffff # mask to enable exceptions sll $t2 $t1 16 # RC address ori $t3 $0 2 # RC enable bit sw $t3 0($t2) # enable keyboard intrerrupt xor $t1 $t1 $t3 # clear exception level mtc0 $t1 $12 # enable bits in status register li $t0 0 # "time" counter count: li $t1 2500000 # simulate 1 second busy: addi $t1 $t1 -1 bnez $t1 busy addi $t0 $t0 1 # 1 second simulated ori $v0 $0 4 # print string la $a0 msg syscall # "\n Elapsed Time = " or $a0 $0 $t0 ori $v0 $0 1 # print integer syscall # simulated time beqz $s0 next # buffer is empty ori $v0 $0 4 # print string la $a0 nl syscall # "\n" or $a0 $0 $s3 # buffer address addu $v1 $a0 $s0 # address of current position sb $0 0($v1) # null terminate buffer syscall # show buffer contents ori $s0 $0 0 # zero current offset next: addi $t1 $t0 -20 # 20 seconds ? bnez $t1 count ori $v0 $0 10 # return to system syscall