How Do You Program a Sequential LED Light Pattern in MIPS Assembly?

AI Thread Summary
The discussion focuses on programming a sequential LED light pattern in MIPS assembly, specifically lighting up LEDs 1-5 one at a time and then cycling back to the first LED. The user is encountering an issue where the register $7 is equating to 0, which affects the intended output. Suggestions include using a time delay to ensure each LED remains lit long enough to be visible, as the current code may execute too quickly for the LEDs to appear on. Additionally, there is mention of using coprocessor 0 for timing functions in MIPS, indicating a need for further exploration of timing mechanisms. The user seeks assistance in troubleshooting their code and understanding the timing aspect in MIPS programming.
Jd303
Messages
34
Reaction score
0
Hi all,
I've only just started MIPS and have been stuck on this introductory lab for a while now.

I have 8 LEDs each lit by there corresponding bit being a 1.
Hence 0010 0101 at the input would light up LEDS 1, 3 and 6.

I need to make LEDs 1-5 light up one at a time and extinguish the previous one
Hence a sequence like this:
0000 0001
0000 0010
0000 0100
0000 1000
0001 0000
0000 0001 As you can see here it should then go back to the first LED being lit.

I realize you can do this with shift left logical, or multiplication. But as it is introductory I have to do this by adding a register with itself to do the same as multiplying a register by 2.

I think this addition is where something is going wrong as my $7 for some reason equates to 0.
Here is my code:

Code:
	.set noreorder 
	.text 
	.globl start 
	.ent start 
	
start: 	lui $9, 0xbf90 		# Load upper half of port address 
		nop
		li $6, 0xff
		li $7, 0x01
repeat: lbu $8, 0x0($9)		# Read from the input port
	nop			# Needed after load
	or $8, $8, $6
	and $8, $8, $7
	sb  $8, 0x0($9) 	# Write to the output port 
	nop			# Another nop for the sb
	bne $7, 5, ELSE
	nop
	addi $7, $7, -4
	b repeat 		# Repeat the read and write cycle 
	nop 			# Needed after branch  
	ELSE: 
	add $7, $7, $7
	b repeat 		# Repeat the read and write cycle 
	nop 			# Needed after branch  
.end start 			# Marks the end of the program

Any help would be greatly appreciated as I really have no clue what is wrong. Thanks in advance
 
Physics news on Phys.org
I'm no programmer but just looking at the comments in your code I see no time delay mentioned. So is it possible it's working fine but too fast? Each LED would only be ON for 1/5th of the time so they appear off? Just a thought.
 
Can you time delay in MIPS?
 
As I said I'm not very familiar with MIPS but most processors have some sort of timer capable of generating interrupts. Google suggests this is in "coprocessor 0” but perhaps wait for someone who knows what they are taking about.
 

Similar threads

Back
Top