The system has 4 push buttons, named A to D. The push buttons are memory mapped to address 0xffffe440. The status of the buttons are given at bit indices 7 through 4, where button A is given at index 7 and button D at index 4. A bit value 1 means that the button is currently pushed. The system has 8 LED lights, memory mapped at address 0x17880010. The LED lights are located at bit indices 12 through 5.
What to do:
Create a program that loops forever. In the loop, read the status of the push buttons A and D, and turn on the LED lights to show the binary representation of the decimal value 13 if A is pressed. If A is released, value 13 should continue to be displayed, until button D is pressed. If D is pressed, all LED lights should be turned off. If button A is pressed again, value 13 should be displayed again, etc. If both A and D are pressed at the same time, the LEDs should be turned off. When the program starts, and no buttons are pressed, all LEDs should be turned off. Note that you can get points for a partially correct solution.
When writing to the memory mapped I/O port, you do not have to take into consideration if some of the other unused bits of the port are changed.
What I have tried:
This is what I have tried, the solution in the answers is very short, but mine is long and probably not a beautiful but it looks correct to me I wanna hear what you guys think. (The reason I don't want to just rewrite it is because I wanna know whether this is correct or not, I am doing old exams)
funct :
lui $t0, 0xffff
ori $t0, $t0, 0xe440
lui $t1, 0x1788
ori $t1, $t1, 0x0010
loop :
lw $t2, 0($t0)
andi $t3, $t2, 0x90
addi $t4, $0, 0x90
bne $t3, $t4, check_A
andi $t9, $t9, 0x0
sw $t9, 0($t1)
j loop
check_A :
andi $t3, $t2, 0x80
addi $t4, $0, 0x80
bne $t3, $t4, check_D
andi $t9, $t9, 0x1a0
sw $t9, 0($t1)
j loop
check_D:
addi $t4, $0, 0x10
andi $t4, $0, 0x10
bne $s3, $t4, exit
andi $t9, $t9, 0x0
sw $t9, 0 ($t1)
j loop
exit:
j loop