MIPS help anyone?

Recommended Posts

I'm trying to convert decimal into binary number the problem i'm having is storing the result into the array and print them out. I am not sure exactly if I am doing this correctly guessing not since its not working. Maybe someone with mips experience can help

This is the buffer :
  numberBuffer: 	.space 128	#holds the converted number. Holds upto 32 integers

This is the basic loop :
	lw $t0, inputNumber #save a copy of the inputted number li$t1, 0 # current index	li $t2, 2 # base number la$t3, numberBuffer #save the base address of the buffer	beq $0,$t0,FINISHED_BINARY_CONVERSION #while inputNumber != 0 DO	div $t0,$t2	#save $t0/$t2 result in special register	mflo $t0 #sets t0 =$t0/2	mfhi $t4 #save the modulus,$t4 = $t0 mod 2 add$t5,$t3,$t1	#save next element address        sb $t4,($t5) 	#save the result into current array address	addi $t1,$t1,1	#increment counter		j LOOPFINISHED_BINARY_CONVERSION:	la $a0,newLine #print a new line li$v0,4	syscall		la $a0,numberBuffer #print the converted value ( I realize its backwards for now) li$v0,4	syscall

Share on other sites
It's been a bit too long since I had to code in MIPS for me to remember exactly how to help you. But, one thing I can suggest is using good tools. I assume you're doing this as homework? When we had to do this for class, the Professor forced us to work using a very simple command-line interpretor for labs.

If your situation is something like that, try writing or debugging your code in something like Mars so you can be sure of what is happening with the values in the registers. I also found when doing my lab work ahead of time that Mars gives much better and more helpful error messages than other tools I tried.

I hope that helps. ^_^

Share on other sites
hey thanks. Not to long before your post, I found mars thats a much better IDE than PCSPIM. But I finished this last night. I ended up printing each byte by byte instead of the whole string. I feel dirty.

Create an account

Register a new account

• Forum Statistics

• Total Topics
627711
• Total Posts
2978744

• 21
• 14
• 12
• 36
• 30