I'm trying to call the function fgets to read from standard input. How do I get the FILE* stdin in assembly?
I'm using nasm on cygwin.
Thanks in advance.
So, I have been doing some digging, and figured out how to use the system calls _write and _read, that use file descriptors instead of a FILE*.
I found some references to a function called fileptr that returns a FILE* corresponding to a file descriptor, but that doesn't seem to be part of the C standard library.
Anyway, here is my test code. It builds and runs correctly under Cygwin.
; test_io.asm ; Test _read and _write system calls ; ; nasm -o test_io.o -fwin32 test_io.asm ; gcc -o test_io test_io.o section .data prompt db 'Enter a string: ',0 prompt_len equ $ - prompt BUFSZ equ 1024 STDIN equ 0 STDOUT equ 1 section .bss buffer resb BUFSZ section .text global _main extern _read, _write _main: push prompt_len push prompt push STDOUT call _write add esp, 12 push BUFSZ - 1 ; leave space for terminating 0 push buffer push STDIN call _read add esp, 12 push eax ; _read returns string length in eax push buffer push STDOUT call _write add esp, 12 mov eax, 0 ret
That would seem to be the way to go.
FILE*'s are constructed by the C runtime library, which may necessitate you dragging in a whole lot of stuff you didn't want. If you did want it, there would seem to be little point in writing this bit in ASM.
I am developing a simple job card creator application with VB.net 2012, using Access 2010 as database.
The code I have generated to write data from a datagridview to the database table is successfully saving the data, but with an error "Parameter @name has no default value". The ...
write a C++ program which take inputs from the user/keyboard and calculate his ZAKAT.
get the input from user may include
-Amount invested in business
-Amount given to other business partners as loan
-Amount payable to others
I made a prime number finder, it finds the nearest prime that is above and below any integer (Does not work that well with giant numbers.)
Made this in cpp.sh
Why would I need the x=y+1-1;?
x=y; just doesnt seem to work
Why is this?
And I know my coding ...