According to the documentation for fgets(), the function takes three parameters:
- 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
I have no trouble calling the function. I just push the three parameters onto the stack, call the function, and increase ESP by 12.
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.
Update: I’m using NASM on Linux.
The problem with
stdinis 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 sacrificestdioand use POSIX calls instead,stdinis the same as the well-known file descriptor #0. You can therefore pass0toreadand get almost what you were looking for. I’m pretty sure this is more assembler-friendly than thestdinC macro.