2

I want to compile assembly code via double-clicking a batch file in the directory of my .asm file. The reason is because the NASM call has few parameters and I want to bypass this step each time.

I wrote a batch that works, but only if you double-click the NASM shortcut on the desktop (this calls nasmpath.bat and opens a command prompt window), and then type out the batch file and press enter in the opened (Windows 10) command prompt.

I attempted to make a batch that calls nasmpath.bat, then proceeds to automatically compile, but nothing happens.

Here's my batch file build.bat (not working):

call C:\Users\Nick\AppData\Local\bin\NASM\nasmpath.bat
del /Q foo.flp
nasm foo.asm -f bin -o foo.flp -l foo.lst

Also, here is nasmpath.bat:

@set path=C:\Users\Nick\AppData\Local\bin\NASM;%path%
@%comspec%
psychosys
  • 57
  • 1
  • 6
  • What does nasmpath.bat look like? A syntax error or an `exit` statement in there would prevent the rest of build.bat from running – Kevin May 06 '18 at 23:30
  • EDITED: Added the contents of the .bat above. – psychosys May 06 '18 at 23:36
  • Comment out `@%comspec%` with `@rem %comspec%` and then try it. The role of *nasmpath.bat* has changed, yet seems you have not adapted the code for the change. – michael_heath May 06 '18 at 23:43
  • @michael_heath I tried changing the .bat like you said, but still no luck double-clicking the .bat file. For the record the .asm file is in the folder C:\Users\Nick\OneDrive\Documents\Foo\ I don't know if that changes anything. – psychosys May 07 '18 at 00:26
  • 1
    If you open a console window where **build.bat** is and run it from the console, then you may see a error message. I suspect you get an error of invalid characters i.e. double quote the path string like `@set "path=C:\Users\Nick\AppData\Local\bin\NASM;%path%"`. – michael_heath May 07 '18 at 00:33
  • After running nasmpath.bat the command prompt window opens and I can run build.bat via typing&enter key. It will create the .lst and .flp file just fine. BUT... what I want to do....just double click a single icon to do all of this together. An alternative is welcome. What I don't get, and I think this is a Windows question, is why I need to run the nasmpath.bat each time I want to run NASM. – psychosys May 07 '18 at 01:47
  • You may not need to run **nasmpath.bat**. See my answer. – michael_heath May 07 '18 at 03:39
  • 1
    Just as extra background, what was happening before is that build.bat was calling nasmpath.bat, which was then launching a new instance of cmd.com (that's what the `@%comspec%` line did), and then leaving you stuck in that new cmd.com. If you were to type `exit` to leave that new cmd.com, it would have gone back to the batch files and proceeded to run the rest of your commands, although obviously that's not what you want in the end. – Kevin May 08 '18 at 16:36

1 Answers1

2

build.bat:

@echo off
set "path=%LocalAppData%\bin\NASM;%path%"
del /Q foo.flp
nasm foo.asm -f bin -o foo.flp -l foo.lst

You may not need to call nasmpath.bat as you are just updating the PATH variable. Calling nasmpath.bat with the same path as the path being added to PATH seems like a duplication of a path i.e. you need to know the path to call the other script.

This script will work in current directory.

michael_heath
  • 5,262
  • 2
  • 12
  • 22