汇编语言(AssemblyLanguage)是面向机器的程序设计语言。在汇编语言中,用助记符(Memoni)代替机器指令的操作码,用地址符号(Symbol)或标号(Label)代替指令或操作数的地址,如此就增强了程序的可读性并且降低了编写难度,象这样符号化的程序设计语言就是汇编语言,因此亦称为符号语言。使用汇编语言编写的程序,机器不能直接识别,还要由汇编程序或者叫汇编语言编译器转换成机器指令。汇编程序将符号化的操作代码组装成处理器可以识别的机器指令,这个组装的过程称为组合或者汇编。因此,有时候人们也把汇编语言称为组合语言。
工具/原料
AssemblyLanguageMasm汇编编译器
方法/步骤
1、打开masm汇编编译程序,新建一个masm源文件脚本。DATASSEGMENT;此处输入数据段代码DATASENDSSTACKSSEGMENT;此处输入堆栈段代码STACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AX;此处输入代码段代码MOVAH,4CHINT21HCODESENDSENDSTART
2、在正文中输入我们的程序代码,并将文件命名为dazi.asmstacksegme艘绒庳焰ntparastack'sta艘早祓胂ck'db256dup(0)toplabelwordstackendsdatasegmentparapublic'data'bufferdb16hdup(0)bufpt1dw0bufpt2dw0kbflagdb0promptdb'xiaobowelcomeyoutoplay',0dh,0ah,'*****Designedby1wangxiaobo@163.com!*****',0dh,0ah,'^HenanUniversityofEconomicsandLaw^date:2014/4/24',0dh,0ah,'*pleasepractisetyping*',0dh,0ah,'$'scantabdb0,0,'1234567890-=',8,0db'qwertyuiop[]',0dh,0db'asdfghjkl;',0,0,0,0db'zxcvbnm,./',0,0,0db'',0,0,0,0,0,0,0,0,0,0,0,0,0db'789-456+1230.'evenoldcs9dw?oldip9dw?str1db'abcdefghijklmnopqrstuvwxyz.'db0dh,0ah,'$'str2db'therearesomenewspapersonthetable.'db0dh,0ah,'$'str3db'therearesomecloudsinthesky.'db0dh,0ah,'$'str4db'shealwayseatsherlunchatnoon.'db0dh,0ah,'$'str5db'idonotlikeautumnandwinter.'crlfdb0dh,0ah,'$'colondb':','$'evensaddrdwstr1,str2,str3,str4,str5countdw0secdw0mindw0hoursdw0save_lcdw2dup(?)dataendscodesegmentassumecs:code,ds:data,es:data,ss:stackmainprocfarstart:movax,stackmovss,axmovsp,offsettoppushdssubax,axpushaxmovax,datamovds,axmoves,ax;movah,0;moval,4;int21h;movah,0bh;movbh,0;movbl,4;int11hmovah,35hmoval,09hint21hmovoldcs9,esmovoldip9,bxpushdsmovdx,segkbintmovds,dxmovdx,offsetkbintmoval,09hmovah,25hint21hpopdsmovah,35hmoval,1chint21hmovsave_lc,bxmovsave_lc+2,espushdsmovdx,segclintmovds,dxmovdx,offsetclintmoval,1chmovah,25hint21hpopdsinal,21handal,11111100bout21h,alfirst:movah,0moval,3int10hmovdx,offsetpromptmovah,9int21hmovsi,0next:movdx,saddr[si]movah,09hint21hmovcount,0movsec,0movmin,0movhours,0stiforever:callkbgettestkbflag,80hjnzendintpushaxcalldispcharpopaxcmpal,0dhjnzforevermoval,0ahcalldispcharcalldisptimeleadx,crlfmovah,09hint21haddsi,2cmpsi,5*2jnenextjmpfirstendint:clipushdsmovdx,save_lcmovax,save_lc+2movds,axmoval,1chmovah,25hint21hpopdspushdsmovdx,oldip9movax,oldcs9movds,axmoval,09hmovah,25hint21hpopdsstiretmainendpclintprocnearpushdsmovbx,datamovds,bxleabx,countincwordptr[bx]cmpwordptr[bx],18jnereturncallinctadj:cmphours,12jlereturnsubhours,12return:popdsstiiretclintendpinctprocnearmovwordptr[bx],0addbx,2incwordptr[bx]cmpwordptr[bx],60jneexitcallinctexit:retinctendpdisptimeprocnearmovax,mincallbindecmovbx,0moval,':'movah,0ehint10hmovax,seccallbindecmovbx,0moval,':'movah,0ehint10hmovbx,countmoval,55dmulblcallbindecretdisptimeendpbindecprocnearmovcx,100dcalldecdivmovcx,10dcalldecdivmovcx,1calldecdivretbindecendpdecdivprocnearmovdx,0divcxmovbx,0addal,30hmovah,0ehint10hmovax,dxretdecdivendpkbgetprocnearpushbxclimovbx,bufpt1cmpbx,bufpt2jnzkbget2cmpkbflag,0jnzkbget3stipopbxjmpkbgetkbget2:moval,[buffer+bx]incbxcmpbx,16hjckbget3movbx,0kbget3:movbufpt1,bxpopbxretkbgetendpkbintprocnearpushbxpushaxinal,60hpushaxinal,61horal,80hout61h,alandal,7fhout61h,alpopaxtestal,80hjnzkbint2movbx,offsetscantabxlatscantabcmpal,0jnzkbint4movkbflag,80hjmpkbint2kbint4:movbx,bufpt2mov[buffer+bx],alincbxcmpbx,16hjckbint3movbx,0kbint3:cmpbx,bufpt1jzkbint2movbufpt2,bxkbint2:climoval,20hout20h,alpopaxpopbxstiiretkbintendpdispcharprocnearpushbxmovbx,0movah,0ehint10hpopbxretdispcharendpcodeendsendstart
3、运行我们编辑的文件打字计时练习的程序,在缓冲区中预放了一些字母,运行时,可按照屏幕上显示的字母输入练习,每输入完一行按回车键后,可显示出练习输入的时间.