Windows中的NASM,Hello World示例比较

时间:2017-06-01 17:17:03

标签: windows assembly x86 nasm

这两个例子,做同样的事情,他们只打印一条"Hello, World!"消息:

示例1:

global  _main
extern  _printf

section .text
   _main:
       push message
       call _printf
       add esp, 4

       ret

   message:
       db "Hello, World!", 13, 10, 0

这是命令行:

nasm -fwin32 0.asm gcc 0.obj

例2:

global _main
extern _ExitProcess@4, _printf

section .text
    _main:
        push message
        call _printf
        add esp, 4

        push 0
        call _ExitProcess@4

    message:
        db "Hello, World!", 13, 10, 0

这是命令行:

nasm -fwin32 0.asm gcc 0.obj

我的问题是,何时使用_ExitProcess@4功能?什么时候只使用ret

1 个答案:

答案 0 :(得分:1)

main()返回通常会产生exit(),而ExitProcess()会调用main();但是如果你在汇编中写作,你通常会得到原始入口点,而不是ExitThread(),从中返回final Xstream xstream = new Xstream(); final Person myPerson = new Person(); Writer writer = new StringWriter(); try { writer.write("<?xml version=\"1.0\"?>"); } catch (final IOException e) { e.printStackTrace(); System.exit(0); //just for testing sakes } final String xmlResponse = xstream.toXML(myPerson, writer); // the line that has the error in Eclipse

有关原始入口点的更多信息:https://blogs.msdn.microsoft.com/oldnewthing/20110525-00/?p=10573/