Skip to content

Instantly share code, notes, and snippets.

@quazi-irfan
Created November 18, 2017 17:24
Show Gist options
  • Save quazi-irfan/c41ccabda1fd5632027a2a1af58eb47e to your computer and use it in GitHub Desktop.
Save quazi-irfan/c41ccabda1fd5632027a2a1af58eb47e to your computer and use it in GitHub Desktop.
DOS Batch Script file
@echo off
REM Assignment 7
REM Check if the file exits.
if not exist %1 (
echo File not found '%1'
exit /b 1
)
REM PRINT FIRST FIVE LINE OF COMMENTS
@echo.
echo ____________FIRST 5 LINES OF SOURCE FILE %1____________
SET /A lineNum=0
FOR %%d IN (@%1) DO (
set /A lineNum=%lineNum+1
echo %d
IF %lineNum EQ 4 goto :endofcmnt
)
:endofcmnt
echo ____________FIRST 5 LINES OF SOURCE FILE %1____________
@echo.
REM RENAME source.asm to source
set aa=%1
set /a length=%@len[%aa]
set bb=%@reverse[%aa]
set cc=%@substr[%bb, 4, %length]
set dd=%@reverse[%cc]
REM SOURCE
type %1 > %dd
REM COMPILE AND LINK
@echo. >> %dd
@echo. >> %dd
@echo. >> %dd
@echo. >> %dd
echo _____COMPILE and LINK :: %dd.asm _____ >> %dd
masm %dd.asm >> %dd
if exist %dd.obj (
link %dd.obj,,,util; >> %dd
)
REM Run the executable file if it exists, or Print error message
if not exist %dd.exe (
@echo.
echo ERROR: Compilation/Linking Failed, open '%dd' file for details.
goto :cleanup
)
:runAgain
@echo.
echo ____________RUN %1____________
%dd.exe
input Do you want to run again(y/n) %%yn
if %yn == y (
goto :runAgain
)
:cleanup
REM CLEANUP
@echo.
if exist %dd.asm (
DEL %dd.asm > nul
echo Deleting %dd.asm
)
if exist %dd.obj (
DEL %dd.obj > nul
echo Deleting %dd.obj
)
if exist %dd.exe (
DEL %dd.exe > nul
echo Deleting %dd.exe
)
if exist %dd.map (
DEL %dd.map > nul
echo Deleting %dd.map
)
echo ____________END of %1____________
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment