I am wrtiing a program in PLP assembly that repeatedly reads the value of the switches (address: 0xf0100000
) and displays a pattern on the LED array (address: 0xf0200000
) based on what switches are clicked. Each time the switch value is read, the pattern should be displayed (regardless of whether the switch value has changed or not since the last time it was read).
The outputs are supposed to be the following:
0: Flash all LEDS
1: Flash all even numbered LEDS
2: Flash all odd numbered LEDS
3: Cycle through each numbered LED one by one
Other Switch: Turn off all LEDS
I have written the following code according to my pseudocode notes and it should work. It assembles and runs, but there is no LED output when any switches are pressed. At first I thought not including the nop
after each break might be the issue but this didn't change anything.
Does anyone see any errors?
# main source file
.org 0x10000000
li $t0, 0xf0100000 #Switch adrress
li $t1, 0xf0200000 # LED adress
Loop1:
lw $t2, 0($t0)
li $t3, 0x00000001 #Checks if 1 pressed
beq $t2, $t3, case1 #Then sends to case1
lw $t2, 0($t0)
li $t3, 0x00000002 #2 presssed
beq $t2, $t3, case2 #sends to case 2
lw $t2, 0($t0)
li $t3, 0x00000004 #3 pressed
beq $t2, $t3, case3 #sends to case 3
lw $t2, 0($t0)
li $t3, 0x00000008 #4 pressed
beq $t2, $t3, case4 #sends to case 4
li $t3, 0x00000000
sw $t3, 0($t1)
j Loop1
nop
case1:
li $t3, 0x000000ff
sw $t3, 0($t1)
li $t3, 0x00000000
sw $t3, 0($t1)
j Loop1
nop
case2:
li $t3, 0x00000055
sw $t3, 0($t1)
li $t3, 0x00000000
sw $t3, 0($t1)
j Loop1
nop
case3:
li $t3, 0x000000aa
sw $t3, 0($t1)
li $t3, 0x00000000
sw $t3, 0($t1)
j Loop1
nop
case4:
li $t3, 0x00000001
sw $t3, 0($t1)
li $t3, 0x00000002
sw $t3, 0($t1)
li $t3, 0x00000004
sw $t3, 0($t1)
li $t3, 0x00000008
sw $t3, 0($t1)
li $t3, 0x00000010
sw $t3, 0($t1)
li $t3, 0x00000020
sw $t3, 0($t1)
li $t3, 0x00000040
sw $t3, 0($t1)
li $t3, 0x00000080
sw $t3, 0($t1)
j Loop1
nop
I think that the problem is mainly related to the time during which your leds are on. I do not know what is the frequency of your system but admitting that it is 10Mhz, the duration during which your leds will be on is counted in ms.
In your code the lw $ t2, 0 ($ t0) are redundant I think. the nops too.
A basic way to insert delay is by using a loop like:
li $t4, val
wait_x:
addi $t4, $t4, -1
bgtz $t4, wait_x
you need to find the val that match the performances of your system. If it still too fast you can add some nops in the loop.
User contributions licensed under CC BY-SA 3.0