Skip to content

Instantly share code, notes, and snippets.

@quazi-irfan
Created December 3, 2017 04:19
Show Gist options
  • Save quazi-irfan/a66461966b79ad184a5dd016109a15b3 to your computer and use it in GitHub Desktop.
Save quazi-irfan/a66461966b79ad184a5dd016109a15b3 to your computer and use it in GitHub Desktop.
Assignment 7 Script
@echo off
REM Assignment 7 GCD : Compile and link two files
REM Check if both files exits.
if not exist %1 (
@echo.
echo File not found '%1'
exit /b 1
)
if not exist %2 (
@echo.
echo File not found '%2'
exit /b 1
)
REM PRINT FIRST FIVE LINE OF COMMENTS
@echo.
echo SCRIPT:____________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 :endofcmnt1
)
:endofcmnt1
echo SCRIPT:____________FIRST 5 LINES OF SOURCE FILE %1____________
@echo.
REM PRINT FIRST FIVE LINE OF COMMENTS
@echo.
echo SCRIPT:____________FIRST 5 LINES OF SOURCE FILE %2____________
SET /A lineNum=0
FOR %%d IN (@%2) DO (
set /A lineNum=%lineNum+1
echo %d
IF %lineNum EQ 4 goto :endofcmnt2
)
:endofcmnt2
echo SCRIPT:____________FIRST 5 LINES OF SOURCE FILE %2____________
@echo.
pause
REM Save arguments in variables
set first=%1
set /a lenfir=%@len[%first]
set tsrif=%@reverse[%first]
set subtsrif=%@substr[%tsrif, 4, %lenfir]
set subfirst=%@reverse[%subtsrif]
set sec=%2
set /a lensec=%@len[%sec]
set ces=%@reverse[%sec]
set subces=%@substr[%ces, 4, %lensec]
set subsec=%@reverse[%subces]
REM COMPILING
masm %subfirst.asm
if not exist %subfirst.obj (
@echo.
echo SCRIPT:____________COMPILING %subfirst.asm FAILED____________
goto :cleanup
)
@echo.
echo SCRIPT:____________COMPILING %subfirst.asm SUCCESS____________
masm %subsec.asm
if not exist %subsec.obj (
@echo.
echo SCRIPT:____________COMPILING %subsec.asm FAILED____________
goto :cleanup
)
@echo.
echo SCRIPT:____________COMPILING %subsec.asm SUCCESS____________
REM LINKING
link %subfirst.obj + %subsec.obj,,,util;
if not exist %subfirst.exe (
@echo.
echo SCRIPT: ____________LINKING %subfirst.asm and %subsec.asm FAILED____________
goto :cleanup
)
@echo.
echo SCRIPT:____________LINKING %subfirst.asm and %subsec.asm SUCCESS____________
:runAgain
@echo.
@echo.
echo SCRIPT:____________RUN %subfirst.exe____________
%subfirst.exe
@echo.
@echo.
input SCRIPT:_________Do you want to run %subfirst.exe again(y/n) %%yn
if %yn == y (
goto :runAgain
)
echo SCRIPT:____________END of run %subfirst.exe____________
:cleanup
REM Delete all intermediate files
@echo.
if exist %subfirst.obj (
DEL %subfirst.obj > nul
)
if exist %subsec.obj (
DEL %subsec.obj > nul
)
if exist %subfirst.map (
DEL %subfirst.map > nul
)
if exist %subsec.map (
DEL %subsec.map > nul
)
if exist %subfirst.exe (
DEL %subfirst.exe > nul
)
if exist %subsec.exe (
DEL %subsec.exe > nul
)
echo SCRIPT:____________DELETING all .obj, .map and .exe file____________
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment