学会批处理

2019-09-19 07:12:48丽君


@echo off 
::close echo
cls
::clean screen                                                           
echo            This programme is to make the MASM programme automate  
::display info
echo                           Edit by CODERED                     
::display info
echo                   Mailto me : qqkiller***@sina.com              
::display info
if "%1"=="" goto usage      
::if input without paramater goto usage
if "%1"=="/?" goto usage    
::if paramater is "/?" goto usage
if "%1"=="help" goto usage  
::if paramater is "help" goto usage 
pause     
::pause to see usage
masm %1.asm    
::assemble the .asm code
if errorlevel 1 pause & edit %1.asm   
::if error pause to see error msg and edit the code
link %1.obj & %1       
::else link the .obj file and execute the .exe file
:usage                      
::set usage
echo Usage: This BAT file name [asm file name] 
echo Default BAT file name is START.BAT 
::display usage

   先不要被这一堆的东西给吓怕了,静下心来仔细的看(回想一下第一章中第一段是怎么写的!!)。已经给出了每一行命令的解释,两个冒号后面的内容为前一行内容解释的E文(害怕E文的朋友也不用担心,都很easy,一看就懂了,实在不懂了不会查词典啊,这么懒?),在脚本执行时不显示,也不起任何作用。倒数第5行行首有一个冒号,可不是笔误哦!具体作用后面会详细讲到。此脚本中masm和link是汇编程序和连接程序,必须和edit程序以及你要编辑的源代码(当然还有这个脚本,废话!)一起在当前目录中。使用这个批处理脚本,可以最大可能的减少手工输入,整个过程中只需要按几下回车键,即可实现从汇编源代码到可执行exe文件的自动化转换,并具备智能判断功能:如果汇编时源代码出现错误(汇编不成功),则自动暂停显示错误信息,并在按任意键后自动进入编辑源代码界面;如果源代码汇编成功,则进行连接,并在连接后自动执行生成的exe文件。另外,由于批处理命令的简单性和灵活性,这个脚本还具备良好的可改进性,简单进行修改就可以符合不同朋友的上机习惯。正在学汇编的朋友,一定别忘了实习一下!
相关文章 大家在看