I am trying to print an unsigned integer value from a MIPS register as ASCII text to the console.
In other words, let's pretend $a0 has "0x4ab3c823" in it. I want to print out "4ab3c823" to console in xSPIM.
Here is my attempt. I keep getting the decimal values, not the ASCII. It's only a snipped of the entire program, so I cut out the rest.
.data
printspace: .space 8
.text
printHex:
move $t0,$a0
la $a0,printspace #Save address of 8 blank bytes to $a0
sw $t0,0($a0) #Copys the integer I want to print to $a0's address in memory
li $v0 1
syscall
jr $ra
With some fiddling, I got the following to do what I needed. Posting for future parties sake.
I assume you mean you want hex output, as ASCII output would be with other letters.
I don't think SPIM has hex output. That means you would have to print character by character. That would involve taking $a0 four bits at a time, and adding a constant (depending on if it's between 0-9 or A-F) to turn it into a printable ASCII character.
In the MARS simulator,
li $v0 34
prints in hex.