step1: http://download.csdn.net/download/xqq524148626/1937262 从此处下载随书源码包。解压安装根目录下的setup,按默认会在c:\安装Masm615.
C:\Masm615\Examples即为书上源码。
step2: 修改 C:\Masm615\INCLUDE\irvine32.inc
在INCLUDE SmallWin.inc 此行后加上
includelib kernel32.lib
includelib user32.lib
includelib Irvine32.lib
三行。修改后部分内容如下:
INCLUDE SmallWin.inc ; MS-Windows prototypes, structures, and constants includelib kernel32.lib includelib user32.lib includelib Irvine32.lib .NOLIST
step3: 建立批处理文件:c:\iasm.bat
path=C:\Masm615;%path% set lib=C:\Masm615\LIB;%lib% set include=C:\Masm615\INCLUDE;%include%
step4: 运行cmd ->转到 C:\Masm615\Examples\ch03 -> 运行c:\iasm.bat 初始path.
step4: assembling & link
C:\Masm615\Examples\ch03>ML.EXE /c /coff /Cp /nologo AddSub.asm Assembling: AddSub.asm C:\Masm615\Examples\ch03>LINK32.EXE /SUBSYSTEM:CONSOLE /RELEASE /VERSION:4.0 AddSub.obj Microsoft (R) Incremental Linker Version 6.00.8447 Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
step5: 运行。输入 AddSub
output:
C:\Masm615\Examples\ch03>AddSub EAX=00030000 EBX=7EFDE000 ECX=00000000 EDX=00401000 ESI=00000000 EDI=00000000 EBP=0018FF94 ESP=0018FF8C EIP=00401014 EFL=00000206 CF=0 SF=0 ZF=0 OF=0
###############################################################
查找资源时,转了不少弯!以下为备注信息。
C:\Masm615\Examples\ch03>ml /? Microsoft (R) Macro Assembler Version 6.15.8803 Copyright (C) Microsoft Corp 1981-2000. All rights reserved. ML [ /options ] filelist [ /link linkoptions ] /AT Enable tiny model (.COM file) /omf generate OMF format object file /Bl<linker> Use alternate linker /Sa Maximize source listing /c Assemble without linking /Sc Generate timings in listing /Cp Preserve case of user identifiers /Sf Generate first pass listing /Cu Map all identifiers to upper case /Sl<width> Set line width /Cx Preserve case in publics, externs /Sn Suppress symbol-table listing /coff generate COFF format object file /Sp<length> Set page length /D<name>[=text] Define text macro /Ss<string> Set subtitle /EP Output preprocessed listing to stdout /St<string> Set title /F <hex> Set stack size (bytes) /Sx List false conditionals /Fe<file> Name executable /Ta<file> Assemble non-.ASM file /Fl[file] Generate listing /w Same as /W0 /WX /Fm[file] Generate map /WX Treat warnings as errors /Fo<file> Name object file /W<number> Set warning level /FPi Generate 80x87 emulator encoding /X Ignore INCLUDE environment path /Fr[file] Generate limited browser info /Zd Add line number debug info /FR[file] Generate full browser info /Zf Make all symbols public /G<c|d|z> Use Pascal, C, or Stdcall calls /Zi Add symbolic debug info /H<number> Set max external name length /Zm Enable MASM 5.10 compatibility /I<name> Add include path /Zp[n] Set structure alignment /link <linker options and libraries> /Zs Perform syntax check only /nologo Suppress copyright message
C:\Masm615\Examples\ch03>link32 /? Microsoft (R) Incremental Linker Version 6.00.8447 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. usage: LINK [options] [files] [@commandfile] options: /ALIGN:# /BASE:{address|@filename,key} /COMMENT:comment /DEBUG /DEBUGTYPE:{CV|COFF} /DEF:filename /DEFAULTLIB:library /DELAY:{NOBIND|UNLOAD} /DELAYLOAD:dll /DLL /DRIVER[:{UPONLY|WDM}] /ENTRY:symbol /EXETYPE:DYNAMIC /EXPORT:symbol /FIXED[:NO] /FORCE[:{MULTIPLE|UNRESOLVED}] /GPSIZE:# /HEAP:reserve[,commit] /IMPLIB:filename /INCLUDE:symbol /INCREMENTAL:{YES|NO} /LARGEADDRESSAWARE[:NO] /LIBPATH:dir /LINK50COMPAT /MACHINE:{ALPHA|ARM|IX86|MIPS|MIPS16|MIPSR41XX|PPC|SH3|SH4} /MAP[:filename] /MAPINFO:{EXPORTS|FIXUPS|LINES} /MERGE:from=to /NODEFAULTLIB[:library] /NOENTRY /NOLOGO /OPT:{ICF[,iterations]|NOICF|NOREF|NOWIN98|REF|WIN98} /ORDER:@filename /OUT:filename /PDB:{filename|NONE} /PDBTYPE:{CON[SOLIDATE]|SEPT[YPES]} /PROFILE /RELEASE /SECTION:name,[E][R][W][S][D][K][L][P][X] /STACK:reserve[,commit] /STUB:filename /SUBSYSTEM:{NATIVE|WINDOWS|CONSOLE|WINDOWSCE|POSIX}[,#[.##]] /SWAPRUN:{CD|NET} /TSAWARE[:NO] /VERBOSE[:LIB] /VERSION:#[.#] /VXD /WARN[:warninglevel] /WINDOWSCE:{CONVERT|EMULATION} /WS:AGGRESSIVE
link的时/SUBSYSTEM:选项很重要,若为 /SUBSYSTEM:WINDOWS,即认为是gui程序,不会往控制台输出东西,所以得赋以选项/SUBSYSTEM:CONSOLE.
期间也有想到用IDE去编译:
RadAsm确实也是个很优秀的工具。
它可以与masm32集成到一起。
关于它们的集成与配置参考:
http://apps.hi.baidu.com/share/detail/31114688
或: http://wenku.baidu.com/view/780dddc65fbfc77da269b1e1.html
#############################################
ML.EXE /c /coff /Cp /nologo AddSub.asm
assembly时/coff 选项也很重要,它控制生成COFF的对象文件,默认是生成OMF的对象文件。
关于两者的差别:http://stackoverflow.com/questions/966597/whats-the-difference-between-the-omf-and-coff-format
Answer nicked out of "MetaWINDOW FAQ - OMF vs COFF Object File Formats.htm"
Since the dawn of PC civilization up until about the time Microsoft Win32 programming tools came along, almost all PC compilers produced object files using the Intel Object Module Format (OMF) standard. Later, Intel introduced 386 processors and 32-bit protected-mode at which point they also expanded the OMF specification for 32-bits, leading to "OMF-386" which became the standard for most PC protected-mode environments. Around this same time, the original Windows NT development team was also designing code, not only for Intel processors, but also to support processors from other vendors. The Microsoft NT team selected a more portable object module format known as Common Object File Format (COFF) derived from the official object-code format for UNIX System V. COFF object modules later became the defacto standard for all Microsoft Win32 development tools, and gained an advantage in being much closer in format to Portable Executable files - the native executable format for Win32 (a COFF-format linker has much less work to create a 32-bit EXE or DLL from a COFF file than from an OMF format file).
Just as there are OMF- and COFF-format object files (.obj's), there are also OMF and COFF format library files (.lib's). The libraries, fortunately, are basically just a collection of the object files, along with some header information that lets the linker determine which object files to use from the library. To make things difficult however, both OMF and COFF use the same file name extensions, .obj and .lib, to reference the two different types of object and library file formats (because of this you can't just look at the file name extension to tell if the object module or library file is OMF or COFF).
The problem with mixing object files and library files from different compiler vendors is that some vendors support COFF, other vendors use OMF, and a few can handle both. Borland, for example, still uses OMF object files and libraries, while Microsoft's 32-bit compilers produce COFF format files. Watcom C/C++ v11.0 seems to prefer COFF when compiling and linking Windows applications, but generates OMF object files for use with their DOS4GW 32-bit protected-mode DOS-extender. Along with this, Microsoft MASM 6.13 produces OMF files by default, but with the /coff switch can emit COFF object files instead.
When it comes time to link files with different formats, different linkers do differnt things. For example, the Microsoft Visual C/C++ linker is designed for COFF format object files and libraries, but will try to convert OMF object files into COFF files if necessary. This works in some cases, but unfortunately Microsoft LINK does not support all OMF record types, so in many situations the linker may still fail when given OMF format object files. Also while Microsoft LINK attempts some support for OMF object files, it will refuse to process any OMF format libraries. Other linkers, such as Borland's TLINK, are designed for OMF object files and will similarly refuse to work with COFF-format object or library files. Some DOS extender and embedded system vendors, such as Phar Lap, provide their own linkers which support both OMF and COFF, giving you a choice.
The bottom line is that mixing OMF and COFF object and library file types can be a mess (plus the cryptic error messages from the linkers don't help). Unless your linker specifically supports it, you should stick with recommended object and library format for your compiler/linker/platform, and avoid mixing OMF and COFF files.
############################################################
PS: 可以不用 ml, link 去一步步编译链接,而用源码中已写好的批处理,内容如下:
C:\Masm615\make32.bat
REM make32.bat - Batch file for assembling/linking 32-bit Assembly programs REM Revised: 11/15/01 @echo off cls REM The following three lines can be customized for your system: REM ********************************************BEGIN customize SET PATH=C:\Masm615 SET INCLUDE=C:\Masm615\INCLUDE SET LIB=C:\Masm615\LIB REM ********************************************END customize ML -Zi -c -Fl -coff %1.asm if errorlevel 1 goto terminate REM add the /MAP option for a map file in the link command. LINK32 %1.obj irvine32.lib kernel32.lib /SUBSYSTEM:CONSOLE /DEBUG if errorLevel 1 goto terminate dir %1.* :terminate pause
make32 AddSub
Microsoft (R) Macro Assembler Version 6.15.8803 Copyright (C) Microsoft Corp 1981-2000. All rights reserved. Assembling: AddSub.asm Microsoft (R) Incremental Linker Version 6.00.8447 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. Volume in drive C has no label. Volume Serial Number is 2685-A06F Directory of C:\Masm615\Examples\ch03 22/12/2011 AM 11:34 316 AddSub.asm 22/12/2011 PM 05:26 28,724 AddSub.exe 22/12/2011 PM 05:26 29,952 AddSub.ilk 22/12/2011 PM 05:26 13,564 AddSub.lst 22/12/2011 PM 05:26 3,462 AddSub.obj 22/12/2011 PM 05:26 91,136 AddSub.pdb 6 File(s) 167,154 bytes 0 Dir(s) 109,293,719,552 bytes free Press any key to continue . . . C:\Masm615\Examples\ch03>AddSub EAX=00030000 EBX=7EFDE000 ECX=00000000 EDX=00401005 ESI=00000000 EDI=00000000 EBP=0018FF94 ESP=0018FF8C EIP=00401024 EFL=00000206 CF=0 SF=0 ZF=0 OF=0