Issues with MIPS interrupt for tv remote simulator
- by pred2040
Hello
I am writing a program for class to simulate a tv remote in a MIPS/SPIM enviroment. The functions of the program itself are unimportant as they worked fine before the interrupt so I left them all out. The gaol is basically to get a input from the keyboard by means of interupt, store it in $s7 and process it. The interrupt is causing my program to repeatedly spam the errors:
Exception occurred at PC=0x00400068
Bad address in data/stack read: 0x00000004
Exception occurred at PC=0x00400358
Bad address in data/stack read: 0x00000000
program starts here
.data
msg_tvworking:
.asciiz "tv is working\n"
msg_sec:
.asciiz "sec -- "
msg_on:
.asciiz "Power On"
msg_off:
.asciiz "Power Off"
msg_channel:
.asciiz " Channel "
msg_volume:
.asciiz " Volume "
msg_sleep:
.asciiz " Sleep Timer: "
msg_dash:
.asciiz "-\n"
msg_newline:
.asciiz "\n"
msg_comma:
.asciiz ", "
array1: .space 400 # 400 bytes of storage for 100 channels
array2: .space 400 # copy of above for sorting
var1: .word 0 # 1 if 0-9 is pressed, 0 if not
var2: .word 0 # stores number of channel (ex. 2-)
var3: .word 0 # channel timer
var4: .word 0 # 1 if s pressed once, 2 if twice, 0 if not
var5: .word 0 # sleep wait timer
var6: .word 0 # program timer
var9: .float 0.01 # for channel timings
.kdata
var7: .word 10
var8: .word 11
.text
.globl main
main:
li $s0, 300
li $s1, 0 # channel
li $s2, 50 # volume
li $s3, 1 # power - 1:on 0:off
li $s4, 0 # sleep timer - 0:off
li $s5, 0 # temporary
li $s6, 0 # length of sleep period
li $s7, 10000 # current key press
li $t2, 0 # temp value not needed across calls
li $t4, 0
interrupt data here
mfc0 $a0, $12
ori $a0, 0xff11
mtc0 $a0, $12
lui $t0, 0xFFFF
ori $a0, $0, 2
sw $a0, 0($t0)
mainloop:
# 1. get external input, and process it
# input from interupt is taken from $a2 and placed in $s7 #for processing
beq $a2, $0, next
lw $s7, 4($a2)
li $a2, 0
# call the process_input function here
# jal process_input
next:
# 2. check sleep timer
mainloopnext1:
# 3. delay for 10ms
jal delay_10ms
jal check_timers
jal channel_time
# 4. print status
lw $s5, var6
addi $s5, $s5, 1
sw $s5, var6
addi $s0, $s0, -1
bne $s0, $0, mainloopnext4
li $s0, 300
jal status_print
mainloopnext4:
j mainloop
li $v0,10 # exit
syscall
--------------------------------------------------
status_print:
seconds_stat:
power_stat:
on_stat:
off_stat:
channel_stat:
volume_stat:
sleep_stat:
j $ra
--------------------------------------------------
delay_10ms:
li $t0, 6000
delay_10ms_loop:
addi $t0, $t0, -1
bne $t0, $0, delay_10ms_loop
jr $ra
--------------------------------------------------
check_timers:
channel_press:
sleep_press:
go_back_press:
channel_check:
channel_ignore:
sleep_check:
sleep_ignore:
j $ra
------------------------------------------------
process_input:
beq $s7, 112, power
beq $s7, 117, channel_up
beq $s7, 100, channel_down
beq $s7, 108, volume_up
beq $s7, 107, volume_down
beq $s7, 115, sleep_init
beq $s7, 118, history
bgt $s7, 47, end_range
jr $ra
end_range:
power:
on:
off:
channel_up:
over:
channel_down:
under:
channel_message:
channel_time:
volume_up:
volume_down:
volume_message:
sleep_init:
sleep_incr:
sleep:
sleep_reset:
history:
digit_pad_init:
digit_pad:
jr $ra
--------------------------------------------
interupt data here, followed closely from class
.ktext 0x80000180
.set noat
move $k1, $at
.set at
sw $v0, var7
sw $a0, var8
mfc0 $k0, $13
srl $a0, $k0, 2
andi $a0, $a0, 0x1f
bne $a0, $zero, no_io
lui $v0, 0xFFFF
lw $a2, 4($v0) # keyboard data placed in $a2
no_io:
mtc0 $0, $13
mfc0 $k0, $12
andi $k0, 0xfffd
ori $k0, 0x11
mtc0 $k0, $12
lw $v0, var7
lw $a0, var8
.set noat
move $at, $k1
.set at
eret
Thanks in advance.