readint nasm Linux 程序集
有没有一种方法/系统调用/函数可以让我从标准输入读取数字到寄存器中?
目前,我可以读取 9 个字符的字符串。
不幸的是,这不是我想要的,因为我的数字可以是可变长度的(只要它可以在汇编中表示),
例如我希望能够输入“5”以及“66785949”以及负数像“-1123534”,并将其正确表示为汇编中的实际数字,而不是字符串。
我到处都在找所以我决定在这里问。
如果没有简单的方法来做到这一点,是否可以在我的linux nasm汇编代码中使用C的输入/输出函数库?我将如何做到这一点以及如何调用这些函数之一以从标准输入获取数字?
谢谢
Is there a way / system call / a function that lets me read numbers from stdin into a register?
currently I can read in a string of, say, 9 characters.
This is, unfortunately, not what I was looking for since my number could be of variable length (so long it is representable in assembly)
e.g. I want to be able to input "5" as well as "66785949" as well as negative numbers like "-1123534", and have it correctly represented as an actual number in assembly, not a string.
I've been looking everywhere so I decided to ask here.
If there's no easy way to do it, is it possible to use C's input/output function library into my linux nasm assembly code? How would I do that and how would I call one of these functions to get a number from stdin?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,没有系统调用可以做到这一点。是的,如果您不想自己实现的话,您可以轻松调用 atoi()。您只需链接到 C 库 (
-lc
) 并声明外部符号 (extern atoi
)。No, there is no system call to do it. Yes, you can easily call atoi(), if you don't feel like implementing it yourself. You just need to link to the C library (
-lc
) and declare the external symbol (extern atoi
).