问题描述
我正在学习汇编,并且有不同的文件描述符用于读取用户输入.
I am learning assembly and there were different file descriptors used for reading user input.
对于阅读键盘输入,我期望文件描述符为0(stdin),但遇到了文章,其中使用了文件描述符2(stderr).
For reading keyboard entry, I was expecting file descriptor 0 (stdin), but came across this article where file descriptor 2 (stderr) was used.
;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:
However, I've commonly seen ebx set as 0 instead:
;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,它们都可以正常工作而没有问题.您能告诉我哪个是更好的选择吗?还是我应该采用其他最佳实践方法?
I have tried setting ebx to 0 and 2, and they both work fine without issues. Can you explain to me which is the better option to use? Or is there other approaches I should take for best practices?
推荐答案
更好的选择是使用STDIN文件描述符(编号0).不过,您可以使用STDERR流(第2个)(实际上是输出流)进行读取:
The better option is to use the STDIN file descriptor (No. 0). Nevertheless, you can use the STDERR streaM (No. 2) - actually an output stream - for reading:
如果重定向STDIN流,这是一个实际的解决方法.
This is a practical workaround, if the STDIN stream is redirected.
这篇关于汇编:用于读取用户输入的文件描述符0或2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!