如何调用x86汇编与fgets? [英] How to call fgets in x86 assembly?
问题描述
根据为与fgets的文档()
,函数有三个参数:
According to the documentation for fgets()
, the function takes three parameters:
- 的char * - 将一直保持输入的字符串
- INT - 这重新presents的最大字符数的整数读
- FILE * - 一个
FILE *
到流从读
- char * - a string that will hold the input
- int - an integer that represents the maximum number of characters to read
- FILE * - a
FILE *
to the stream to read from
我有麻烦调用该函数。我只是推
三个参数压入堆栈,调用函数,并增加 ESP
12
I have no trouble calling the function. I just push
the three parameters onto the stack, call the function, and increase ESP
by 12.
我的问题是与参数#3。什么应该被传递作为 FILE *
标准输入?在C中,我可以只使用标准输入
,但我不知道是相当于在x86汇编的东西。
My problem is with parameter #3. What should be passed in as the FILE *
for standard input? In C, I can just use stdin
, but I don't know what the equivalent is in x86 assembly.
更新:我在Linux上使用NASM
Update: I'm using NASM on Linux.
推荐答案
与标准输入
的问题是,它是一个可扩展的东西不仅是特定于平台的宏,但最有可能难以从装配手工访问。如果你愿意牺牲 STDIO
和使用POSIX调用代替,标准输入
是一样的知名文件描述符#0。因此,您可以通过 0
来 读
并得到几乎是你所期待的。我是pretty知道这是更加汇编友好比标准输入
C代码宏。
The problem with stdin
is that it's a macro that expands to something not only platform-specific, but most likely difficult to access from assembly by hand. If you're willing to sacrifice stdio
and use POSIX calls instead, stdin
is the same as the well-known file descriptor #0. You can therefore pass 0
to read
and get almost what you were looking for. I'm pretty sure this is more assembler-friendly than the stdin
C macro.
这篇关于如何调用x86汇编与fgets?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!