-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasm32m.bat
255 lines (217 loc) · 10.4 KB
/
asm32m.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
@echo off
rem
rem This is a MS-Windows batch file for assembling and linking assembly language
rem source files. It is designed to be used with the book entitled: Assembly
rem Language for x86 Processors, 6th edition, by Kip R. Irvine. The
rem configuration used here assumes that you are using Microsoft MASM and
rem Visual Studio 2010 (or Visual Studio 2010 Express). This batch file runs
rem under Windows XP, Windows 7 (32-bit), and Windows Vista.
rem
rem Copy this file to a location on your system path.
rem
rem Customization:
rem -----------------------------------------------------------------
rem If Visual Studio is installed in some other directory than
rem C:\Program Files\Microsoft Visual Studio 10, you must modify the
rem SET VSHOME statement (on or near line 130).
rem
rem Syntax for running this file:
rem ------------------------------------------------------------------
rem asm32 - display help
rem asm32 [/H|/h|-H|-h] - display help
rem asm32 filelist - assemble and link
rem asm32 /D filelist - assemble, link, and debug
rem asm32 /C filelist - assemble only
rem
rem A filelist is a list of up to 5 filenames, separated by spaces.
rem The filenames must not have extensions, because .asm is assumed.
rem The first filename determines the name of the exe file produced
rem by the linker.
rem
rem Examples:
rem -----------------------------------------------------------------
rem Display help information (5 ways to do this):
rem asm32
rem asm32 /H
rem asm32 /h
rem asm32 -H
rem asm32 -h
rem
rem Assemble and link myprog.asm, producing myprog.obj and myprog.exe:
rem asm32 myprog
rem
rem Assemble main.asm, producing main.obj:
rem asm32 /C main
rem
rem Assemble main.asm, print.asm, and sum.asm. Then link all three,
rem producing main.exe:
rem asm32 main print sum
rem
rem Assemble main.asm, print.asm, and sum.asm. Then link all three,
rem producing main.exe. Then start main.exe in the debugger:
rem asm32 /D main print sum
rem
rem Credits:
rem -------------------------------------------------------------------
rem This batch file was the result of a collaboration between the
rem following individuals:
rem (1) Kip Irvine, http://asmirvine.com, mailto:[email protected]
rem (2) John I. Moore, Jr., Department of Mathematics and Computer
rem Science, The Citadel, http://mathcs.citadel.edu
rem (3) Gerald Cahill, Antelope Valley College
rem (4) James Brink, Pacific Lutheran University
rem
rem Update History:
rem -------------------------------------------------------------------
rem 02/23/07: created by Kip Irvine and John Moore
rem 02/23/07: revised to display help if no arguments are given
rem 02/24/07: debugging /D switch enabled
rem 02/25/07: linking /L switch removed, /C switch added
rem 02/25/07: permits up to 5 source files to be assembled
rem 02/28/07: when setting INCLUDE, LIB, and PATH commands, existing
rem values values are appended to our settings. Additional
rem command line switches added for displaying help.
rem 03/04/07: Created a loop to permit the linker to link multiple
rem obj files. Examples added to remarks section.
rem 08/26/08: Revised for Visual Studio 2008
rem 01/18/10: Revised for Visual Studio 2010
rem --------------------------------------------------------------------
rem -------------------- BEGIN ACTIVE COMMANDS -----------------------
rem The SETLOCAL command makes all subsequent settings of environment
rem settings local to this batch file. The settings will disappear when
rem the batch file reaches the ENDLOCAL command.
SETLOCAL
rem Check for the /H (help) command
if "%1"=="" goto HELP
if %1==/H goto HELP
if %1==/h goto HELP
if %1==-H goto HELP
if %1==-h goto HELP
rem -----------------------------------------------------------------
rem CHECK COMMAND-LINE SWITCHES
rem -----------------------------------------------------------------
rem If the first argument is /C, disable LINKING and shift the
rem remaining arguments backward one position.
rem -----------------------------------------------------------------
set LINKING=yes
if %1 NEQ /C goto CHECK_DEBUG_SWITCH
shift
set LINKING=no
:CHECK_DEBUG_SWITCH
rem -----------------------------------------------------------------
rem If the first argument is /D, enable the DEBUG option
rem and shift the remaining arguments backward one position.
rem -----------------------------------------------------------------
set DEBUG=no
if %1 NEQ /D goto DELETE_FILES
shift
set DEBUG=yes
:DELETE_FILES
rem ----------------------------------
rem Delete the old object file
rem ----------------------------------
if exist %1.obj del %1.obj
rem -----------------------------------------------------------------
rem PREPARE THE ENVIRONMENT VARIABLES
rem
rem Set the VS_HOME environment variable to the location of Visual
rem Studio 2010 (or Visual C++ 2010 Express)
rem -----------------------------------------------------------------
set VS_HOME=C:\Program Files\Microsoft Visual Studio 10.0
rem -----------------------------------------------------------------
rem Add Visual Studio to the system path.
rem -----------------------------------------------------------------
set PATH=%VS_HOME%\VC\bin;%VS_HOME%\Common7\IDE;%PATH%
rem -----------------------------------------------------------------
rem Set the INCLUDE environment variable to the location of the
rem MASM include files used by Irvine's book.
rem -----------------------------------------------------------------
set INCLUDE=%CD%\Lib;%INCLUDE%
rem -----------------------------------------------------------------
rem Set the LIB environment variable to the location of the
rem Link libraries used by Irvine's book.
rem -----------------------------------------------------------------
set LIB=%VS_HOME%\VC\LIB;%CD%\Lib;%LIB%
rem -----------------------------------------------------------------
rem EXECUTE THE ASSEMBLER
rem Parameters:
rem -nologo suppress the Microsoft logo
rem -c assemble only
rem -Zi generate debugging information
rem %%F source filename, held in loop variable
rem -----------------------------------------------------------------
for %%F in (%1 %2 %3 %4 %5) do ml -nologo -c -Zi %%F.asm
if errorlevel 1 goto QUIT
rem (the preceding IF statement only affects the last source file to be assembled)
rem ---------------------------------
rem Find out if linking is disabled
rem ---------------------------------
if %LINKING%==no goto QUIT
rem -----------------------------------------------------------------------------------------
rem EXECUTE THE LINKER
rem Parameters:
rem /NOLOGO (suppress the Microsoft logo display)
rem /DEBUG (include debugging information)
rem /SUBSYSTEM:CONSOLE (generate a Windows Console-aware application)
rem irvine32.lib, kernel32.lib, user32.lib (link libraries)
rem %1 (EXE filename produced by the linker)
rem ------------------------------------------------------------------------------------------
echo.
echo Linking Assembler output files to the Irvine32, Kernel32, and User32 libraries.
SET LINKCMD=link /NOLOGO /DEBUG /SUBSYSTEM:CONSOLE irvine32.lib kernel32.lib user32.lib
SET FILELIST=%1.obj
SET EXENAME=%1.exe
:LINKLOOP
if !%2==! goto ENDLINKLOOP
SET FILELIST=%FILELIST% %2.obj
shift
goto LINKLOOP
:ENDLINKLOOP
rem -------------------------------------------------------------------
rem Execute the linker, using the command line and list of input files.
rem -------------------------------------------------------------------
%LINKCMD% %FILELIST%
if errorlevel 1 goto QUIT
echo.
echo Linker successful. The executable file %EXENAME% was produced.
echo ..................................
echo.
rem Find out if debugging was disabled
if %DEBUG%==no goto QUIT
rem -----------------------------------------------------------------
rem LAUNCH THE VISUAL STUDIO DEBUGGER
rem -----------------------------------------------------------------
echo Launching the Visual Studio debugger...
devenv %1.exe /debugexe
goto QUIT
rem -----------------------------------------------------------------
rem SHOW HELP INFORMATION
rem -----------------------------------------------------------------
:HELP
cls
echo This file assembles, links, and debugs a single assembly language
echo source file. Before using it, install Visual Studio in the following
echo directory: C:\Program Files\Microsoft Visual Studio 10.0
echo.
echo Next, install the Irvine 6th edition link libraires and include files
echo in the following directory: %CD%\Lib
echo.
echo Finally, copy this batch file to a location on your system path. We recommend
echo the following directory: C:\Program Files\Microsoft Visual Studio 10.0\VC\bin
echo.
echo Command-line syntax:
echo.
echo asm32 [/H ^| /h ^| -H ^| -h] -- display this help information
echo asm32 filelist -- assemble and link all files
echo asm32 /D filelist -- assemble, link, and debug
echo asm32 /C filelist -- assemble only
echo.
echo ^<filelist^> is a list of up to 5 filenames (without extensions),
echo separated by spaces. The filenames are assumed to refer to files
echo having .asm extensions. Command-line switches are case-sensitive.
rem -----------------------------------------------------------------
rem BATCH FILE EXIT POINT
rem -----------------------------------------------------------------
:QUIT
rem ENDLOCAL clears all local environment variable settings.
ENDLOCAL