string 在 MIPS 中打印字符串和变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2692087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Printing a string and variable in MIPS
提问by hodgesmr
Here's the C representation of what I'm trying to do in MIPS assembly:
这是我在 MIPS 程序集中尝试执行的操作的 C 表示:
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= ,我也可以做一个系统调用来打印 int x (它存储在寄存器中)。但是,它会像这样打印它们(假设 x 是 5):
x=
5
x=
5
How can I make them print on the same line?
如何让它们打印在同一行上?
回答by Paul R
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.
查看 Fibonacci.asm 示例:http: //courses.missouristate.edu/KenVollmar/MARS/Fibonacci.asm- 这似乎是您需要做什么的一个很好的示例 - 查看print:
标签附近的部分。看起来您需要syscall 4
打印x =
零件和syscall 1
打印整数本身。
回答by ndim
Use a syscall for printing the x=
which does not add a line feed.
使用系统调用来打印x=
不添加换行符的。
What that syscall might be is system specific, and you are not mentioning anything about the system.
该系统调用可能是特定于系统的,并且您没有提及有关系统的任何内容。
回答by WhirlWind
If you print with two separate characters, 'x' and '=', you should avoid the newline problem.
如果使用两个单独的字符 'x' 和 '=' 打印,则应避免换行问题。