简体   繁体   English

readint nasm Linux程序集

[英]readint nasm linux assembly

Is there a way / system call / a function that lets me read numbers from stdin into a register? 有没有一种方法/系统调用/函数可以让我从stdin读取数字到寄存器中?

currently I can read in a string of, say, 9 characters. 目前,我可以读9个字符的字符串。

This is, unfortunately, not what I was looking for since my number could be of variable length (so long it is representable in assembly) 不幸的是,这不是我想要的,因为我的数字可以是可变长度的(只要它可以在汇编中表示)

eg 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. 例如,我希望能够输入“ 5”,“ 66785949”以及诸如“ -1123534”的负数,并使其正确地表示为汇编中的实际数字,而不是字符串。

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? 如果没有简便的方法,是否可以在我的Linux nasm汇编代码中使用C的输入/输出函数库? How would I do that and how would I call one of these functions to get a number from stdin? 我该怎么做,如何调用这些函数之一来从stdin获取数字?

Thanks 谢谢

No, there is no system call to do it. 不,没有系统调用可以执行此操作。 Yes, you can easily call atoi(), if you don't feel like implementing it yourself. 是的,如果您不想自己实现它,则可以轻松地调用atoi()。 You just need to link to the C library ( -lc ) and declare the external symbol ( extern atoi ). 您只需要链接到C库( -lc )并声明外部符号( extern atoi )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM