I'm writing a batch file for building MASM32 program automatically called
mkmasm.bat, like this:
@echo off
set MASM32DIR=C:\masm32
set MASM32BIN=%MASM32DIR%\bin
set MASM32INC=%MASM32DIR%\include
set MASM32LIB=%MASM32DIR%\lib
set ASMFILE = %1
set OBJFILE = %ASMFILE:.asm=.obj%
set EXEFILE = %OBJFILE:.obj=.exe%
%MASM32BIN%/ml.exe /I %MASM32INC% /c /coff /Cp %1
%MASM32BIN%/link.exe /subsystem:console /release /machine:ix86 /libpath:%MASM32LIB% /out:%EXEFILE% %OBJFILE%
And here's the test program, called
test.asm:
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib
.data
MsgBoxText db "Hello world"
MsgCaption db "MASM32"
.code
start:
invoke MessageBox,NULL,offset MsgBoxText,offset MsgCaption,MB_OK
invoke ExitProcess,NULL
end start
Invoking
mkmasm test.asm should produce the executable. Instead, it gives me an error message:
Quote
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.
Assembling: test.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
LINK : fatal error LNK1146: no argument specified with option "/out:"
What's wrong, anyway, since typing the command manually gives the correct result... :dazzled:
What's wrong with passing "test" as the parameter instead of "test.asm"?
It's not a good idea to put spaces in a SET command :wink
set ASMFILE=%1
set OBJFILE=%ASMFILE:.asm=.obj%
set EXEFILE=%OBJFILE:.obj=.exe%
Quote from: jdoe on January 07, 2009, 06:54:31 AM
It's not a good idea to put spaces in a SET command :wink
Stupid me. :green
Anyway, thanks for the input. It works. :U
jdoe: You beat me to it :U
In all fairness to me, I went looking at "set/?" and got sidetracked...5 pages of (quite interesting) help :dazzled:
i know this is an old thread, but....
i wanted to add "Build" to the right-click context menu for asm files
if i am working on console mode stuff, i don't mind opening a console window
and - i know - in QEditor (et al), the menu option is there
but i wanted it in explorer, too, for working on GUI programs
adding Build to the context menu was simple enough
but i had a little problem with extensions
the batch file expects only the base filename, then adds ".asm", ".obj", ".exe"
explorer wants to pass the entire name
well - a little search on the forum, and i found this thread
i noticed he used batch file text "substition"
well, i came up with one that is slightly different
upon entry, the batch file expands the "%1" parameter as "SomeFile.asm"
set parmfile=%1
set parmfile=%parmfile:~0,-4%
this strips the last 4 characters off the string
now, %parmfile% will expand to "SomeFile", with no period or extension
the beauty is, if you have a file with a base name that has a period, the method still works
"Some.File.asm" will be stripped to "Some.File"
although, not sure if ML or LINK will accept it :P
also - the 4 characters are stripped, regardless of case - the extension can be ".aSm"
i can probably make it a one-step process by using "%%"
i also need a little test to make sure it was a ".asm" file to begin with :P
i couldn't make it work in one step, which is ok
this works pretty well...
@echo off
set parmfile=%1
set parmext=%parmfile:~-4%
if /i not "%parmext%"==".asm" goto NotAsmExt
:: /i switch used for case insensitive compare
:: command extensions must be enabled (default)
set parmfile=%parmfile:~0,-4%
:: %parmfile% now expands to filename base
echo %parmfile%
goto BatEnd
:NotAsmExt
echo not an asm file
:BatEnd