I have the following source for an assembly program that I got in a Youtube video tutorial:
.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, addr buffer, 100
invoke ExitProcess, 0
end start
I compile the program with a bat file
ml /c /coff %1.asm
Link /SUBSYSTEM:WINDOWS %1.OBJ
I call the bat file assemble.bat so I call assemble source and it assembles the executable.
The problem is that when I run the program (the pro开发者_运维问答gram assembles fine with no errors) the program simply does nothing. I call it in the console prompt and it simply does nothing, the program just shows a blank line and goes back to the command prompt as if nothing happened.
In the video tutorial the guy assembled his program and compiled and worked fine, but for me nothing happens.
I solved the problem.
It was not working cause I was linking with the command "Link /SUBSYSTEM:WINDOWS %1.OBJ" For console applications the linking command should be "Link /SUBSYSTEM:CONSOLE %1.OBJ".
At least normally StdIn
and StdOut
will be the handles to the standard input and output. To read/write, you'd need to invoke functions like ReadFile
and WriteFile
, passing StdIn
or StdOut
as parameters designating the file to read/write respectively.
Edit: here's a short example:
.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
Add right after the MODEL flat statement:
includelib \masm32\lib\kernel32.lib ;fixed the problem!
精彩评论