如何在 mips 汇编中打印大于 32 位的数字?

发布于 2024-08-20 03:02:28 字数 163 浏览 2 评论 0原文

在我的 mips 汇编代码中,我使用了 multi 指令来乘以 2 个大数,因为结果无法容纳在一个寄存器中。这意味着该数字保存在 hi 和 lo 特殊寄存器中。我的问题是如何打印乘法的结果。我可以访问 hi 和 lo 并将它们放入其他寄存器中(即 $t0,$t1),但我不知道如何组合这两个数字以打印结果。谢谢。

In my mips assembly code, I used the multi instruction to multiply 2 large numbers since the result could not fit in one register. This means that the number is saved in the hi and lo special registers. My problem is how do I print the result of the multiplication. I can access hi and lo and put them in other registers (i.e. $t0, $t1), but I do not know of a way to combine the two numbers in order to print the result. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情绪操控生活 2024-08-27 03:02:28

(这个答案故意保持高水平,因为我很确定没有人在 mips 汇编中打印数字,除非他们是为了家庭作业而这样做。)

如果您不介意以十六进制形式获取它,那没问题;只需以十六进制打印一个单词,然后打印下一个单词。不要忘记在第二个单词上包含前导零! (实际上我认为 spim,我猜你正在使用它,只能以 10 为基数打印,所以即使这可能有点麻烦)。

如果你想要它以 10 为基数,这个问题很快就会进入我称之为“痛苦”的类别。在“现实生活”中,我不会打扰;用 C 进行打印,某处的某个编译器人员为您解决了所有这些问题。对于家庭作业,您可以自己编写一个函数,将输入重复除以 10,最终您将得到要打印出来的数字。如果 mips 没有 64 位除法指令(我无法告诉你),这对你来说将是一个非常有趣的问题。

(This answer kept deliberately high-level, since I'm pretty sure no one prints numbers in mips assembly unless they're doing it for a homework assignment.)

If you don't mind getting it in hex, it's no problem; just print one word in hex, and then the next one. Don't forget to include the leading zeroes on the second word! (Actually I think spim, which I presume you're using, can only print in base 10, so even this might be a bit of a chore).

If you want it in base 10, this problem quickly heads into the category I would call 'pain-in-the-ass'. In 'real life', I wouldn't bother; do the printing in C, some compiler guy somewhere solved all these problems for you. For homework, write yourself a function that divides the input by 10 repeatedly and you'll eventually end up with the digits to print out. If mips doesn't have a 64-bit divide instruction (couldn't tell you off the top of my head) this is going to be a pretty fun problem for you to solve.

铁轨上的流浪者 2024-08-27 03:02:28

打印数字的解决方案实际上是将数字重复除以 10,并获取除法的其余部分并将其存储在字符串中,然后倒过来读取。但唯一的挑战是如果 mips32 只有 32 位除法,则对 64 位数字进行除法。我在此页面找到了一种方法:

https://www. codeproject.com/questions/714114/how-to-print-bit-in

the solution to print the number is really dividing the number repeatedly by 10 and get the rest of division and store in a string and then read it upside down. But the only challenge is divide the 64-bit number if the mips32 only have 32-bits division. I find a way in this page:

https://www.codeproject.com/questions/714114/how-to-print-bit-in

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文