The MASM Forum

General => The Campus => Topic started by: g6g6 on June 13, 2014, 03:52:43 AM

Title: Fatal Error: cannot open input file .EXE!
Post by: g6g6 on June 13, 2014, 03:52:43 AM
Hello,I am new with MASM32... And I am studying the book Assembly Language for x86 processors sixth edition . So, this book give me this code:

.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
DumpRegs PROTO
.code
main PROC
mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
call DumpRegs
INVOKE ExitProcess,0
main ENDP
END main

And, I created an ASM file, and I assemble with the ml asm.asm command. But, appears the following:

Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/z2
"asm.obj"
"asm.exe"
NUL
LINK : warning LNK4044: unrecognized option "z2"; ignored
asm.obj : warning LNK4033: converting object format from OMF
LINK : fatal error LNK1181: cannot open input file "asm.exe"

What is wrong??? Tks
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: dedndave on June 13, 2014, 04:19:41 AM
the linker probably gets a /z2 switch if you run ML without the /c switch
here's the deal....
ML will run LINK automatically to create an EXE
if the ML and LINK versions aren't a match, ML may pass invalid switches
we usually disable this feature by using /c, which means "assemble only - do not link"
we very often add resource files - so the auto-link feature is undesirable, anyways

the OMF error is issued because, for 32-bit programs, the COFF format is used
using the ML /coff switch will do this for you

the "unable to open EXE" error may be caused by a few things
if you are not using ML /c, and you run LINK immediately after ML, perhaps the EXE may not have closed
but, the most often cause of this is that you.....
1) assemble a program
2) run it - it fails to close
3) you make some changes, and try to assemble again
4) because the program is still running, the OS will not allow LINK to write to the EXE

you can fix that by terminating any previous instances with the Task Manager
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: dedndave on June 13, 2014, 04:20:47 AM
to assemble a simple console mode program....

Code: [Select]
ml /c /coff MyProgram.asm
link /SUBSYSTEM:CONSOLE MyProgram.obj
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: g6g6 on June 13, 2014, 04:29:21 AM
oh, tks! I understand.. But, now, with your commands, says:

C:\masm32\bin>ml /c /coff asm.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights re

 Assembling: asm.asm

C:\masm32\bin>link /SUBSYSTEM:CONSOLE asm.obj
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights res

asm.obj : error LNK2001: unresolved external symbol _ExitProcess@4
asm.obj : error LNK2001: unresolved external symbol _DumpRegs@0
asm.exe : fatal error LNK1120: 2 unresolved externals
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: dedndave on June 13, 2014, 04:35:00 AM
i knew you were gonna say that   :biggrin:

that example is from Kip Irvine's book
you need to use Kip's include files and libraries to make it work

if you don't have them on CD, you can get them online

http://kipirvine.com/asm/examples/ (http://kipirvine.com/asm/examples/)
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: dedndave on June 13, 2014, 04:37:00 AM
i suggest you download and install the masm32 package
masm32 should be installed on the root folder of the drive you want to use for projects

then, get Kip's libraries
and create a folder \masm32\Irvine32
and put Kip's stuff in there
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: g6g6 on June 13, 2014, 04:46:49 AM
Okk, but, what commands should I use? Because the Irvine package is in another directory..
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: dedndave on June 13, 2014, 04:47:42 AM
this is not the best way to do this
Kip has an INC file that takes care of the PROTOtypes

but, it is simple...
Code: [Select]
        .386
        .MODEL  Flat,StdCall

        INCLUDELIB  Kernel32.lib
        INCLUDELIB  Irvine32.lib

ExitProcess PROTO :DWORD
DumpRegs    PROTO

        .code

main    PROC

        mov     eax,10000h    ; EAX = 10000h
        add     eax,40000h    ; EAX = 50000h
        sub     eax,20000h    ; EAX = 30000h
        call    DumpRegs
        INVOKE  ExitProcess,0

main    ENDP

        END     main

notice there is no STACK declaration for Flat model

also....
i used short paths for the LIB files, and assembled with them in the same folder

if you set up for visual studio, as Kip's book suggests,
then Kip tells you where to put the files
and the INCLUDE and LIB environment variables take care of that for you

i don't use VS - i use masm32
so - paths are hard-coded and root-relative
in that case, you may have to adjust the INCLUDELIB statements with a path
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: dedndave on June 13, 2014, 04:49:07 AM
result...
Code: [Select]
  EAX=00030000  EBX=7FFD8000  ECX=0012FFB0  EDX=7C90E514
  ESI=00000000  EDI=00000010  EBP=0012FFF0  ESP=0012FFC4
  EIP=00401014  EFL=00000206  CF=0  SF=0  ZF=0  OF=0  AF=0  PF=1
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: Vortex on June 13, 2014, 04:52:05 AM
Hi g6g6,

If you download the Masm32 package, you can try the code below :

Code: [Select]
.386
.model flat, stdcall
option casemap:none

ExitProcess PROTO :DWORD
printf      PROTO C :VARARG

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\msvcrt.lib

.data

message     db 'eax = %Xh',0

.code

main PROC

    mov     eax,10000h
    add     eax,40000h

    call    DumpReg

    invoke  ExitProcess,0

main ENDP

DumpReg PROC

    invoke  printf,ADDR message,eax
    ret

DumpReg ENDP

END main

To build the executable :

Code: [Select]
\masm32\bin\ml /c /coff DumpReg.asm
\masm32\bin\polink /SUBSYSTEM:CONSOLE DumpReg.obj
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: dedndave on June 13, 2014, 05:02:23 AM
i think this will work if you have set up the files as directed in Kip's book
Code: [Select]
        INCLUDE     Irvine32.inc
        INCLUDE     FloatIO.inc
        INCLUDE     GraphWin.inc
        INCLUDE     Macros.inc
        INCLUDELIB  Kernel32.lib
        INCLUDELIB  User32.lib
        INCLUDELIB  Irvine32.lib
that gets you everything, including the processor and model - and the PROTO's
i believe the environment variables are set up for you
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: g6g6 on June 13, 2014, 05:09:07 AM
Thank you dedndave! Thank you Vortex! I t works with the code of the Vortex!... But, I really did not understand why.. I am studying assembly, but is is really hard.. I would to know if you have any books that help me, that explains...Tks, If you could explain why is works... I will be very glad
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: dedndave on June 13, 2014, 05:14:45 AM
ExitProcess is an operating system function - the actual code is in kernel32.dll (windows system folder)
the same is true of functions that display console text, like those used in DumpRegs (Irvine32 function)
DumpReg (masm32 function) also uses msvcrt.dll

when you assemble the code, the OBJ file lists the external function symbols
but - you must "resolve" those externals when you LINK to create an EXE file
so - an import library is used to resolve them
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: g6g6 on June 13, 2014, 05:28:23 AM
hmm, now I get it.. Very thank you!!
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: g6g6 on June 13, 2014, 05:33:45 AM
One more thing: Do you have a list of the dll that each function uses?
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: dedndave on June 13, 2014, 06:17:12 AM
there are thousands   :biggrin:

if you want to look inside the DLL's, you can use a free program called Dependency Walker

but - it's much easier to just look at the include files in \masm32\include
these are plain text files that may be opened with NotePad

if you want to see what's inside kernel32.dll,
most of the functions are prototyped in \masm32\include\kernel32.inc
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: g6g6 on June 13, 2014, 06:21:09 AM
Tks!
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: dedndave on June 13, 2014, 06:22:59 AM
if you want descriptions, microsoft maintains a site called MSDN
most of the functions are documented in the MSDN library

here's a simple example
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682658%28v=vs.85%29.aspx (http://msdn.microsoft.com/en-us/library/windows/desktop/ms682658%28v=vs.85%29.aspx)

they are shown in C syntax, of course
most of us can look at the C code and know the MASM syntax is
Code: [Select]
        INVOKE  ExitProcess,uExitCode
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: g6g6 on June 13, 2014, 06:34:44 AM
Yes, I know this site..Do you thing that with just this book that I am studying I can lear assembly?
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: dedndave on June 13, 2014, 06:42:11 AM
Kip's book is great for learning the basics, like....
data types - numbering systems
basic masm syntax
intel instructions

there are some things that Kip does in an "out of date" way, though
the best example of this is that most of his library functions are passed arguments in register
and - the functions don't typically follow the rules of the windows ABI

per microsoft, things changed drastically between 16-bit DOS and 32-bit Windows
for example, arguments are passed on the stack (not in registers)
many of the methods Kip uses are carry-overs from 16-bit days

as long as you understand that, you can still use Kip's book to learn the basics
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: g6g6 on June 13, 2014, 07:13:24 AM
Yess, tks
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: Gunther on June 14, 2014, 02:01:35 AM
there are some things that Kip does in an "out of date" way, though
the best example of this is that most of his library functions are passed arguments in register
and - the functions don't typically follow the rules of the windows ABI

Always this Kip. I can't recommend him.

Gunther
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: g6g6 on June 14, 2014, 02:35:09 AM
what you recommend?
Title: Re: Fatal Error: cannot open input file .EXE!
Post by: Gunther on June 14, 2014, 04:15:45 AM
what you recommend?

For learning 32-bit Windows programming: Download and install the MASM32 package. It contains a large number of working and well commented examples, tutorials and help files. That should be sufficient for a start. Later are the manuals by Intel and AMD very helpful.

Gunther