Masm32汇编程序无法按预期运行

问题描述

| 我从YouTube视频教程中获得了以下汇编程序源:
.386
.model flat,stdcall
option casemap:none

include c:\\masm32\\include\\windows.inc
include c:\\masm32\\include\\masm32.inc
include c:\\masm32\\include\\kernel32.inc

includelib c:\\masm32\\lib\\masm32.lib
includelib c:\\masm32\\lib\\kernel32.lib

.data
message1 db \"Type your name: \",0
message2 db \"Your name is \",0

.data?
buffer db 100 dup(?)

.code
start:

invoke StdOut,addr message1
invoke StdIn,addr buffer,100
invoke StdOut,addr message2
invoke StdOut,addr buffer

invoke StdIn,100
invoke ExitProcess,0

end start
我用bat文件编译程序
ml /c /coff %1.asm
Link /SUBSYstem:WINDOWS %1.OBJ
我将bat文件称为assemble.bat,所以将其称为assemble source,它会汇编可执行文件。 问题是,当我运行该程序时(该程序可以正常运行且没有错误),该程序完全不执行任何操作。我在控制台提示符下调用它,它什么也没做,该程序仅显示一个空行,并返回到命令提示符,好像什么都没发生。 在视频教程中,那个家伙组装了他的程序,编译并运行良好,但是对我来说什么也没发生。     

解决方法

        我解决了问题。 由于我与命令\“ Link / SUBSYSTEM:WINDOWS%1.OBJ \”链接而无法正常工作 对于控制台应用程序,链接命令应该为\“ Link / SUBSYSTEM:CONSOLE%1.OBJ \”。     ,        至少通常
StdIn
StdOut
是标准输入和输出的句柄。要读取/写入,您需要调用
ReadFile
WriteFile
之类的函数,并传递
StdIn
StdOut
作为参数,分别指定要读取/写入的文件。 编辑:这是一个简短的示例:
.386
.MODEL flat,stdcall

getstdout = -11

WriteFile PROTO NEAR32 stdcall,\\
        handle:dword,\\
        buffer:ptr byte,\\
        bytes:dword,\\
        written: ptr dword,\\
        overlapped: ptr byte

GetStdHandle PROTO NEAR32,device:dword

ExitProcess PROTO NEAR32,exitcode:dword

.stack 8192

.data
message db \"Hello World!\"
msg_size equ $ - offset message

.data?
written  dd ?

.code
main proc   
    invoke GetStdHandle,getstdout
    invoke WriteFile,\\
           eax,\\
           offset message,\\
           msg_size,\\
           offset written,\\
           0
    invoke ExitProcess,0
main endp
        end main
    ,        在MODEL平面语句之后添加:
includelib  \\masm32\\lib\\kernel32.lib   ;fixed the problem!