在 MIPS 中打印字符串和变量
以下是我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 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 needssyscall 4
for printing thex =
part andsyscall 1
for printing the integer itself.使用系统调用来打印不添加换行符的
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.
如果您使用两个单独的字符“x”和“=”进行打印,则应该避免换行问题。
If you print with two separate characters, 'x' and '=', you should avoid the newline problem.