.org 0x10000000
li $sp, 0x10fffffc # Stack pointer initialization
li $s0, sseg_lut # Lookup table address used by sseg_display
lui $s1, 0xf070 # Interrupt controller register
lui $s2, 0xf0a0 # Seven segment display
# ****************************
# TODO: enable interrupts below
# ****************************
li $t0, 0b11 #Value to set the mask to. Set bit pos 0 and 1 to high so we can use interrupts and timer
sw $t0, 0($s1) #Store the value to the mask
li $t1, 0xffffffff #max overflow for ISR
li $t2, 0x00000064 #value of 100. Subtract from the max to get 100 cycles.
li $t3, 0xf0600000 #value of the timer
subu $t1, $t1, $t2 #subtract 100 from the timer's max
sw $t1, 0($t3) #write new overflow value to the timer
li $t4, 0xf0200000 #address of LEDS
li $t5, 0b11111111 #all ones to turn on all the LEDs
li $t6, 0b00000000 #all zeroes to turn off al the LEDs
li $iv, ISR #store the vector
# NOTE: Do not add or modify any code within this main loop
main:
#sw $t0, 0($s1) #If you un comment this, it works as intended.
jal sseg_display
nop
addiu $a0, $a0, 1
j main
nop
# ****************************************
# TODO: add interrupt service routine below
# ****************************************
ISR:
save
lw $i0, 0($t4) #load value of LEDs to i0
lw $i1, 4($s1) #loads the value of the status register to i1
beq $t5, $i0, turnOffLED #t7 - 1
nop #t6 - 0
bne $t5, $i0, turnOnLED
nop
turnOnLED:
sw $t5, 0($t4)
li $i1, 0b11
j end
nop
turnOffLED:
sw $t6, 0($t4)
li $i1, 0b11
j end
nop
end:
sw $i1, 4($s1) #clear interrupts
lw $i1, 0($s1) #get mask register
ori $i1, $i1, 1
restore
jr $ir
sw $i1, 0($s1) #resets all interrupts
The above code is supposed to flash LEDs every 100 clock cycles while a 7 segment display counts up in hex. That part was given to me so I know the counting works. My problem is that it will turn on the LEDs but not turn them off. I think my mask isn't being set correctly and global interrupts are disabled upon exiting the interrupt. I think the end function is what's wrong. Any help would be appreciated!
User contributions licensed under CC BY-SA 3.0