|
看Intel 汇编语言程序设计(第五版)时说可以使用visual studio进行汇编开发和编译,但visual studio 系列工具没有相应的汇编模板。经过研究发现可以手工修改,添加拥有《Intel 汇编语言程序设计(第五版)》的作者写的Irvine库的汇编模板工程:
首先安装《Intel 汇编语言程序设计(第五版)》的库下载地址为http://kipirvine.com/asm/files/IrvineLibHelp.exe,安装到Microsoft Visual Studio 9.0的安装目录下。
打开Microsoft Visual Studio 9.0\VC\vcprojects\,拷贝MC++EmptyProj.ico为ASM Project.ico(默认图标,可以自己制定),创建ASM Project.vsz,内容为
VSWIZARD 7.0
Wizard=VsWizard.VsWizardEngine.9.0
Param="WIZARD_NAME = ASM Project"
Param="RELATIVE_PATH = VCWizards\AppWiz\Generic"
Param="WIZARD_UI = FALSE"
Param="MANAGED = FALSE"
Param="WIZARD_ID = 54"
打开vc.vsdir,在最后添加内容
ASM Project.vsz|{1B027A40-8F43-11D0-8D11-00A0C91BC942}|#1906|30|#1907|{1B027A40-8F43-11D0-8D11-00A0C91BC942}|0|4096|#1154
打开Microsoft Visual Studio 9.0\VC\vcprojects\Win32\下的win32.vsdir,在最后添加内容
..\ASM Project.vsz|{1B027A40-8F43-11D0-8D11-00A0C91BC942}|#1906|1|#1907|{1B027A40-8F43-11D0-8D11-00A0C91BC942}|0|4096|#1154
然后到Visual Studio 9.0\VC\VCWizards路径下添加一个文件:
defaultASM.vcproj,内容为
<?xml version="1.0"?>
<VisualStudioProject ProjectType="Visual C++" Version="9.00" TargetFrameworkVersion="196613" >
<Platforms>
<Platform. Name="Win32"/>
</Platforms>
<ToolFiles>
<DefaultToolFile FileName="masm.rules"/>
</ToolFiles>
<Configurations>
<Configuration Name="Debug|Win32" utputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" ConfigurationType="1" CharacterSet="2">
<Tool Name="VCPreBuildEventTool"/>
<Tool Name="VCCustomBuildTool"/>
<Tool Name="MASM" AssembledCodeListingFile="$(InputName).lst" IncludePaths="D:\Program Files\Microsoft Visual Studio 9.0\Irvine"/>
<Tool Name="VCXMLDataGeneratorTool"/>
<Tool Name="VCWebServiceProxyGeneratorTool"/>
<Tool Name="VCMIDLTool"/>
<Tool Name="VCCLCompilerTool" ptimization="0" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" WarningLevel="3" DebugInformationFormat="4"/>
<Tool Name="VCManagedResourceCompilerTool"/>
<Tool Name="VCResourceCompilerTool"/>
<Tool Name="VCPreLinkEventTool"/>
<Tool Name="VCLinkerTool" AdditionalDependencies="user32.lib kernel32.lib Irvine32.lib" AdditionalLibraryDirectories="D:\Program Files\Microsoft Visual Studio 9.0\Irvine" IgnoreDefaultLibraryNames="" GenerateDebugInformation="true" SubSystem="1" TargetMachine="1"/>
<Tool Name="VCALinkTool"/>
<Tool Name="VCManifestTool"/>
<Tool Name="VCXDCMakeTool"/>
<Tool Name="VCBscMakeTool"/>
<Tool Name="VCFxCopTool"/>
<Tool Name="VCAppVerifierTool"/>
<Tool Name="VCPostBuildEventTool"/>
</Configuration>
<Configuration Name="Release|Win32" utputDirectory="$(SolutionDir)$(ConfigurationName)" IntermediateDirectory="$(ConfigurationName)" ConfigurationType="1" CharacterSet="2" WholeProgramOptimization="1">
<Tool Name="VCPreBuildEventTool"/>
<Tool Name="VCCustomBuildTool"/>
<Tool Name="MASM" AssembledCodeListingFile="$(InputName).lst" IncludePaths="D:\Program Files\Microsoft Visual Studio 9.0\Irvine"/>
<Tool Name="VCXMLDataGeneratorTool"/>
<Tool Name="VCWebServiceProxyGeneratorTool"/>
<Tool Name="VCMIDLTool"/>
<Tool Name="VCCLCompilerTool" ptimization="2" EnableIntrinsicFunctions="true" RuntimeLibrary="2" EnableFunctionLevelLinking="true" WarningLevel="3" DebugInformationFormat="3"/>
<Tool Name="VCManagedResourceCompilerTool"/>
<Tool Name="VCResourceCompilerTool"/>
<Tool Name="VCPreLinkEventTool"/>
<Tool Name="VCLinkerTool" AdditionalDependencies="user32.lib kernel32.lib Irvine32.lib" AdditionalLibraryDirectories="D:\Program Files\Microsoft Visual Studio 9.0\Irvine" GenerateDebugInformation="true" SubSystem="1" ptimizeReferences="2" EnableCOMDATFolding="2" TargetMachine="1"/>
<Tool Name="VCALinkTool"/>
<Tool Name="VCManifestTool"/>
<Tool Name="VCXDCMakeTool"/>
<Tool Name="VCBscMakeTool"/>
<Tool Name="VCFxCopTool"/>
<Tool Name="VCAppVerifierTool"/>
<Tool Name="VCPostBuildEventTool"/>
</Configuration>
</Configurations>
<Files>
<Filter Name="Source Files" Filter="asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
</Filter>
<Filter Name="Header Files" Filter="inc" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
</Filter>
<Filter Name="Resource Files" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;txt" UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" >
</Filter>
</Files>
</VisualStudioProject>
这个是一个模板文件,包含了一些常用的配置(比如Irvine的库的位置,附加的lib文件等,加红路径根据自己情况更改),新建工程时会自动复制到工程目录下。
在Microsoft Visual Studio 9.0\VC\VCWizards\AppWiz\Generic\路径下创建文件夹ASM Project,然后在ASM Project文件夹内创建Scripts\1033\default.js,default.js内容为:
function OnFinish(selProj, selObj)
{
try
{
var strProjectPath = wizard.FindSymbol('PROJECT_PATH');
var strProjectName = wizard.FindSymbol('PROJECT_NAME');
selProj = CreateCustomProject(strProjectName, strProjectPath);
AddConfig(selProj, strProjectName);
var InfFile = CreateCustomInfFile();
AddFilesToCustomProj(selProj, strProjectName, strProjectPath, InfFile);
PchSettings(selProj);
InfFile.Delete();
selProj.Object.Save();
}
catch(e)
{
if (e.description.length != 0)
SetErrorInfo(e);
return e.number
}
}
function CreateCustomProject(strProjectName, strProjectPath)
{
try
{
var strProjTemplatePath = wizard.FindSymbol('PROJECT_TEMPLATE_PATH');
var strProjTemplate = '';
strProjTemplate = strProjTemplatePath + '\\defaultASM.vcproj'; //获得ASM配置模板路径和名称
var Solution = dte.Solution;
var strSolutionName = "";
if (wizard.FindSymbol("CLOSE_SOLUTION"))
{
Solution.Close();
strSolutionName = wizard.FindSymbol("VS_SOLUTION_NAME");
if (strSolutionName.length)
{
var strSolutionPath = strProjectPath.substr(0, strProjectPath.length - strProjectName.length);
Solution.Create(strSolutionPath, strSolutionName);
}
}
var strProjectNameWithExt = '';
strProjectNameWithExt = strProjectName + '.vcproj';
var Target = wizard.FindSymbol("TARGET");
var prj;
if (wizard.FindSymbol("WIZARD_TYPE") == vsWizardAddSubProject) // vsWizardAddSubProject
{
var prjItem = oTarget.AddFromTemplate(strProjTemplate, strProjectNameWithExt);
prj = prjItem.SubProject;
}
else
{
prj = oTarget.AddFromTemplate(strProjTemplate, strProjectPath, strProjectNameWithExt);
}
var fxtarget = wizard.FindSymbol("TARGET_FRAMEWORK_VERSION");
if (fxtarget != null && fxtarget != "")
{
fxtarget = fxtarget.split('.', 2);
if (fxtarget.length == 2)
prj.Object.TargetFrameworkVersion = parseInt(fxtarget[0]) * 0x10000 + parseInt(fxtarget[1])
}
return prj;
}
catch(e)
{
throw e;
}
}
function AddConfig(proj, strProjectName)
{
try
{
var config = proj.Object.Configurations('Debug');
config.IntermediateDirectory = '$(ConfigurationName)';
config.OutputDirectory = '$(ConfigurationName)';
var CLTool = config.Tools('VCCLCompilerTool');
// TODO: Add compiler settings
var LinkTool = config.Tools('VCLinkerTool');
// TODO: Add linker settings
config = proj.Object.Configurations('Release');
config.IntermediateDirectory = '$(ConfigurationName)';
config.OutputDirectory = '$(ConfigurationName)';
var CLTool = config.Tools('VCCLCompilerTool');
// TODO: Add compiler settings
var LinkTool = config.Tools('VCLinkerTool');
// TODO: Add linker settings
var ToolFiles = proj.Object.ToolFiles
}
catch(e)
{
throw e;
}
}
function PchSettings(proj)
{
// TODO: specify pch settings
}
function DelFile(fso, strWizTempFile)
{
try
{
if (fso.FileExists(strWizTempFile))
{
var tmpFile = fso.GetFile(strWizTempFile);
tmpFile.Delete();
}
}
catch(e)
{
throw e;
}
}
function CreateCustomInfFile()
{
try
{
var fso, TemplatesFolder, TemplateFiles, strTemplate;
fso = new ActiveXObject('Scripting.FileSystemObject');
var TemporaryFolder = 2;
var tfolder = fso.GetSpecialFolder(TemporaryFolder);
var strTempFolder = tfolder.Drive + '\\' + tfolder.Name;
var strWizTempFile = strTempFolder + "\\" + fso.GetTempName();
var strTemplatePath = wizard.FindSymbol('TEMPLATES_PATH');
var strInfFile = strTemplatePath + '\\Templates.inf';
wizard.RenderTemplate(strInfFile, strWizTempFile);
var WizTempFile = fso.GetFile(strWizTempFile);
return WizTempFile;
}
catch(e)
{
throw e;
}
}
function GetTargetName(strName, strProjectName)
{
try
{
// TODO: set the name of the rendered file based on the template filename
var strTarget = strName;
if (strName == 'readme.txt')
strTarget = 'ReadMe.txt';
if (strName == 'sample.txt')
strTarget = 'Sample.txt';
if (strName == 'main.asm')
strTarget = 'main.asm';
return strTarget;
}
catch(e)
{
throw e;
}
}
function AddFilesToCustomProj(proj, strProjectName, strProjectPath, InfFile)
{
try
{
var projItems = proj.ProjectItems
var strTemplatePath = wizard.FindSymbol('TEMPLATES_PATH');
var strTpl = '';
var strName = '';
var strTextStream = InfFile.OpenAsTextStream(1, -2);
while (!strTextStream.AtEndOfStream)
{
strTpl = strTextStream.ReadLine();
if (strTpl != '')
{
strName = strTpl;
var strTarget = GetTargetName(strName, strProjectName);
var strTemplate = strTemplatePath + '\\' + strTpl;
var strFile = strProjectPath + '\\' + strTarget;
var bCopyOnly = false; //"true" will only copy the file from strTemplate to strTarget without rendering/adding to the project
var strExt = strName.substr(strName.lastIndexOf("."));
if(strExt==".bmp" || strExt==".ico" || strExt==".gif" || strExt==".rtf" || strExt==".css")
bCopyOnly = true;
wizard.RenderTemplate(strTemplate, strFile, bCopyOnly);
proj.Object.AddFile(strFile);
}
}
strTextStream.Close();
}
catch(e)
{
throw e;
}
}
(责任编辑:admin) |