我正在学习程序集,并且有不同的文件描述符用于读取用户输入。
对于读取键盘条目,我期望文件描述符0 (stdin),但遇到了这个文章,其中使用了文件描述符2 (stderr)。
;Read and store the user input
mov eax, 3
mov ebx, 2
mov ecx, num
mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information
int 80h但是,我通常看到ebx设置为0:
;Read and store the user input
mov eax, 3
mov ebx, 0
mov ecx, num
mov edx, 5 ;5 bytes (numeric, 1 for sign) of that information
int 80h我已经尝试将ebx设置为0和2,它们都可以正常工作,没有问题。你能给我解释一下哪一种选择更好吗?或者,对于最佳实践,我还应该采取其他方法吗?
发布于 2018-07-12 14:44:33
更好的选择是使用STDIN文件描述符(编号0)。然而,您可以使用STDERR streaM (第2号)--实际上是一个输出流--用于读取:
stderr流预计将开放供读写使用。
如果STDIN流被重定向,这是一个实用的解决方案。
https://stackoverflow.com/questions/51307387
复制相似问题