在 MIPS 中打印字符串和变量

发布于 2024-08-30 01:56:58 字数 241 浏览 1 评论 0原文

以下是我在 MIPS 汇编中尝试执行的操作的 C 表示:

printf ("x=%d\n", x);

我知道我可以执行系统调用来轻松打印 x=,并且还可以执行系统调用来打印 int x(存储在寄存器中)。然而,这会像这样打印它们(假设 x 是 5):

x=

5

如何让它们打印在同一行?

Here's the C representation of what I'm trying to do in MIPS assembly:

printf ("x=%d\n", x);

I know that I can do a syscall to easily print x= and I can also do a syscall to print the int x (which is stored in a register). However, that prints them like this (let's say x is 5):

x=

5

How can I make them print on the same line?

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

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

发布评论

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

评论(3

你与清晨阳光 2024-09-06 01:56:58

查看 Fibonacci.asm 示例: http://courses.missouristate.edu/KenVollmar/ MARS/Fibonacci.asm - 这似乎是您需要执行的操作的一个很好的示例 - 查看 print: 标签附近的部分。看起来您需要 syscall 4 来打印 x = 部分,并需要 syscall 1 来打印整数本身。

Look at the Fibonacci.asm example: http://courses.missouristate.edu/KenVollmar/MARS/Fibonacci.asm - it seems to be a good example of exactly what you need to do - look at the part near the print: label. It looks like you needs syscall 4 for printing the x = part and syscall 1 for printing the integer itself.

黑寡妇 2024-09-06 01:56:58

使用系统调用来打印不添加换行符的x=

该系统调用可能是特定于系统的,并且您没有提及有关系统的任何内容。

Use a syscall for printing the x= which does not add a line feed.

What that syscall might be is system specific, and you are not mentioning anything about the system.

流年已逝 2024-09-06 01:56:58

如果您使用两个单独的字符“x”和“=”进行打印,则应该避免换行问题。

If you print with two separate characters, 'x' and '=', you should avoid the newline problem.

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