I/O in NASM programs in Windows 7

倾然丶 夕夏残阳落幕 提交于 2019-12-24 04:05:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!