问题
I want to program in NASM assembly language. I have NASM 2.07 and Borland C++ compiler 5.0 (bcc32). My OS is Windows 7. I do not know how to do input and output with NASM in Windows platform. Please can you help me?
回答1:
If you are this new to NASM, I would suggest not using Borland C++ 5.0. I have a toolkit on my website here that is a complete tool-chain for win32 programming.
You modify main.asm, and run make.bat to compile and link it. It doesn't get any easier than this. The package comes with documentation and an e-book on NASM programming.
回答2:
The easiest way is to call the Win32 functions, accessible by linking the kernel32 libs (IIRC).
回答3:
Install cygwin with nasm. Cygwin is a terminal for windows. Check this tutorial http://www.avivos.net/gcc-g-c-and-cpp-compiler-and-ssh-in-windows-8-cygwin/ Actually It is for installing gcc and g++ but you can select nasm the same way.
回答4:
You can use the "C" functions "printf" and "scanf". For doing that you need to declare it as "extern". There is a simple example:
section .data
input_string db 0
format db "%s", 0
output_string1 db "type something", 10, 0 ; "type something\n"
output_string2 db "you wrote: %s", 0
extern _printf
extern _scanf
section .text
global _main
_main: ; int main()
push output_string1 ;
call _printf ; printf(string1);
add esp, 4 ;
push output_string1 ;
push format ;
call _scanf ; scanf(format, string1);
add esp, 8 ;
push input_string ;
push output_string2 ;
call _printf ; printf(output_string2, input_string);
add esp, 8 ;
xor eax, eax ; return 0;
ret ;
来源:https://stackoverflow.com/questions/2327538/i-o-in-nasm-programs-in-windows-7