打印MIPS注册内容 [英] Print MIPS Register Contents
问题描述
我试图将MIPS寄存器中的无符号整数值作为ASCII文本打印到控制台.
I am trying to print an unsigned integer value from a MIPS register as ASCII text to the console.
换句话说,让我们假设$ a0中包含"0x4ab3c823".我想打印出"4ab3c823"以在xSPIM中进行控制台.
In other words, let's pretend $a0 has "0x4ab3c823" in it. I want to print out "4ab3c823" to console in xSPIM.
这是我的尝试.我一直在获取十进制值,而不是ASCII.这只是整个程序的一部分,因此我将其余部分剪掉.
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
推荐答案
我假设您是要十六进制输出,因为ASCII输出将与其他字母一起显示.
I assume you mean you want hex output, as ASCII output would be with other letters.
我不认为SPIM具有十六进制输出.这意味着您将必须逐个字符地打印.这将涉及一次将$ a0取四位,并添加一个常量(取决于它在0-9还是A-F之间),以将其转换为可打印的ASCII字符.
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.
在MARS模拟器中,li $v0 34
以十六进制打印.
In the MARS simulator, li $v0 34
prints in hex.
这篇关于打印MIPS注册内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!