【发布时间】:2019-05-22 12:07:12
【问题描述】:
但我的导师没有回应。我有一个 MIPS 计划的额外学分问题,如下所示:
Extra credit covers binary to ASCII data type conversion. It is useful
to convert the 2’s complement integer into an ASCII string so that it
can be displayed on the monitor. Derive a binary-to-ASCII conversion
routine, BinarytoASCII, for converting a 2’s complement integer stored
in a0 register into an ASCII string stored in v0 register. The value
initially in a0 is restricted to be within the range -999 to +999. After
the algorithm completes execution, v0 contains the sign of the value
initially stored in a0. The following three bytes contain the three
ASCII codes corresponding to the three decimal digits representing its
magnitude. This algorithm always produces a string of four characters
independent of the sign and magnitude of the integer being converted.
也许我没有正确阅读这个问题,但是将二进制值直接存储到 MIPS 中的寄存器中不是不可能的吗?似乎这要求进行十进制到 ASCII 的转换。如果我错了,你能展示如何将一个基数为 2 的数字放入 MIPS 中的寄存器中吗?谢谢
【问题讨论】:
-
你想多了——你认为以
:)开头的寄存器中存储了什么(所有计算机都知道0或1)所以教授基本上希望你获取寄存器的内容并将其转换为一系列 ASCII'0'和'1'(例如and和shift并添加,例如or和'0'...),然后反转字符串以恢复原始顺序) -
看看asciitable.com。
0x30是'0'和0x31是'1'。 -
@David,他希望将其转换为十进制,而不是二进制。 (但直到最后一句话的下一句才提到十进制。)
-
啊,很好,所以添加手动 base2 到 base10 的转换,而不仅仅是
shift and add。 -
寄存器中的值已经以位编码(MIPS 寄存器在物理上是 32 位(0 或 1)并且 nothing 其他)。当调试器显示
a0包含1234时,它采用原始的32 位模式,并将其解释为整数(即它转换为字符串),并在屏幕上显示,但寄存器仍然只是位模式...(即如果1234是十六进制,那么寄存器在顶部包含 16 个零位,然后是0001_0010_0011_0100...如果是十进制,我懒得将 base10 1234 转换为 base2 ...无论如何,你希望现在就明白了)。
标签: assembly binary ascii mips mars-simulator