News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Fatal Error: cannot open input file .EXE!

Started by g6g6, June 13, 2014, 03:52:43 AM

Previous topic - Next topic

g6g6

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

dedndave

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

dedndave

to assemble a simple console mode program....

ml /c /coff MyProgram.asm
link /SUBSYSTEM:CONSOLE MyProgram.obj

g6g6

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

dedndave

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/

dedndave

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

g6g6

Okk, but, what commands should I use? Because the Irvine package is in another directory..

dedndave

this is not the best way to do this
Kip has an INC file that takes care of the PROTOtypes

but, it is simple...
        .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

dedndave

result...
  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

Vortex

Hi g6g6,

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

.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 :

\masm32\bin\ml /c /coff DumpReg.asm
\masm32\bin\polink /SUBSYSTEM:CONSOLE DumpReg.obj

dedndave

i think this will work if you have set up the files as directed in Kip's book
        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

g6g6

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

dedndave

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

g6g6


g6g6

One more thing: Do you have a list of the dll that each function uses?