《附录二程式语言效率分析.docx》由会员分享,可在线阅读,更多相关《附录二程式语言效率分析.docx(10页珍藏版)》请在第壹文秘上搜索。
1、上一页目录下一页附录二程式语言效率分析附录二程式语言效率分析以下为利用ASSEMBLY,basic,pascal,c,fortran等程式语言,将个24x24之点阵字形,放大成为48x48,并分别比较其处理速度、占用空间以及制作时间。为了正确计算执行时间,特意作10,000次处理,至于指定的24x24字形,则假设为空格。一、ASSEMBLY组合语言变化无穷,先以般的作法,用点阵位移来处理。1PAGE60,1322CGSEGMENT3BUFINDB72DUP(O)45678910:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:3
2、0:31:32:33:34:35:36:37:BUFOTSTART:S3:MVBYTE:MVDB:MVDBl:DB72*4DUP(O)ASSUMECS:CG,DS:CG,ES:CGMOVAX,CGMOVDS,AXMOVES,AXCLDMOVBP,10000;处理10,000次SUBCX,CXMOVBX,CXMOVDX,1803H;计数用MOVSI,OFFSETBUFIN;24*24点阵起始位址MOVDI,OFFSETBUFOT;预定48*48储存位址MOVBH,DL:做三列1.ODSB;取原点阵MOVBL,ALMOVCL,8;做八位元RCLBL,1;左移一次PUSHF;保存状态RCLAX,1;
3、两字同时左移一次POPF:取出原移位状态RCLAX,1;再一次,得双位点值1.OOPMVDBl;八次回路STOSW;存入MOVDI+4,X;上下放大一行DECBH;共3列JNZMVDBADDDI,6;移向次行DECDHJNZMVBYTE;共24行38:DECBP;执行10,000次39:JNZS3;完成40:MOVAX,4C00H41:INT21H42:CGENDS43:ENDSTART本程式制作时间,为十五分钟。经汇编后,得934字元的执行程式,执行耗时14.5秒。若将上段程式加以分析,可以发现到此段程式执行时间全部浪费在23至30这一段回路中。为了增加速度,可以将空间加大,避开回路,连续执
4、行八次移位动作如次:23:RCLBL,124:RCLAX,125:SHLAX,126:同上共八次47:MOVCX,AX;AX中为单位元值48:SHRCX,1;CX得到双位元点阵值49:ORAX,CX;双位元点阵合并似此,程式增大了36字元,但执行时间却减少为7.1秒,速度快了一倍!是不是还是更好的方法呢?相信定多得不计其数。比如说,我们已知原点阵放大倍后点形为双点,以双点做表,取其对应之值,即可免除各点移位的手续,再将原程式第18条以下改为:18:VT2:19:CALLMVBYTE;放大一行20:SUBSI,3;纵向尚须放大一次21:CALLMVBYTE;再放大一行22:DECDH;完成否?2
5、3:JNZVT2;再做24:RET;完成25:MVBYTE:26:MOVCL,DL;一行有三字元27:MVDB:28:LODSB;取一字元29:MOVAH,AL;分置两处30:ANDAX,OFFOH;AH,AL各取四位元31:SHRAL,1;右移四次还原32:SHRAL,133:SHRAL,134:SHRAL,135:MOVBL,AL36:MOVAL,BYTETBBX;左字元取预设表值37:MOVBL,AH38:MOVAH,BYTETBBX;右字元取表值39:STOSW;得二字元置缓冲器中40:LOOPMVDB;做三次41:RET42转换表43:BYTETBDB000H,003H,OOCH,O
6、OFH,030H,033H,03CH,03FH44:DBOCOH,0C3H,OCCH,OCFH,OFOH,0F3H,OFCH,OFFH45:CGENDS46:ENDSTART再换个方法,因为有个XALT的指令,是专为这种程式所设计的。由第25条起,调整如下:25:MVBYTE:26:MOVCL,4;供AL左移四位用27:MOVBX,OFFSETBYTETB28:MVDB:29:LODSB;取一字元30:MOVAH,AL;分置两处31:ANDAX,OFOOFH;AH,AL各取四位元32:SHRAL,CL33:XLAT;将BX+AL值放AL中34:XCHGAL,AH35:XLAT36:STOSW3
7、7:DECDL38:JNZMVDB如此,执行程式959字元,执行速度3.2秒,效率更佳。上述程式的缺点为:在循环过程中,速度有所损失,而且用四位元查表也费事耗时。如果用一字元查表,则需增大表的对应值,再改为总表的方式,次即可查到。且由第20行改起,并力求指令的精简,如:20:MOVDX,OFFSETBYTETB21:MVDB:22:LODSB23:SUBAH,AH24:SHLAX,1;一字元须变为二字元25:ADDAX,DX;之位置以查表26:MOVBX,AX;BX可供间接定址用27:MOVAX,BX;以一字元查表值28:STOSW;查妥存入第一行29:MOVDI+4,AX;上下再重复一行30
8、:LODSB31:SUBAH,AH;处32:SHLAX,1;理33:ADDAX,DX34:MOVBX,AX;第35:MOVAX,BX;二36:STOSW;列37:MOVDI+4,AX38:LODSB39:SUBAH,AH;处40:SHLAX,1;理41:ADDAX,DX42:MOVBX,AX;第43:MOVAX,BXJ三44:STOSW;列45:MOVDI+4,AX46:ADDDI,6;再处理下一行47:LOOPMVDB;共24次48:DECBP;做10,000次49:JNZS3;完成50:MOVAX,4C00H51: INT21H52: RET程式到此为止,下面还有转换总表,可供各程式共用。
9、12;转换表;I10111213141516171819202122232425262728293031323334353637383940414243444546BYTETBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBDBLABELWORD000H,000H,000H,003H,000H,OOCH,000H,OOFH000H,030H,000H,033H,000H,03CH,000H,03FH000H,OCOH,000H,0C3H,000H,OCCH,000H,OCFH00
10、0H,OFOH,000H,0F3H,OOOH,OFCH,OOOH,OFFH003H,OOOH,003H,003H,003H,OOCH,003H,OOI-H003H,030H,003H,033H,003H,03CH,003H,03FH003H,OCOH,003H,0C3H,003H,OCCH,003H,OCFH003H,OFOH,003H,0F3H,003H,OFCH,003H,OFFHOOCH,OOOH,OOCH,003H,OOCH,OOCH,OOCH,OOFHOOCH,030H,OOCH,033H,OOCH,03CH,OOCH,03FHOOCH,OCOH,OOCH,0C3H,OOCH,OCC
11、H,OOCH,OCFHOOCH,OFOH,OOCH,0F3H,OOCH,OFCH,OOCH,OFFHOOFH,OOOH,OOFH,003H,OOFH,OOCH,OOFH,OOFHOOFH,030H,OOFH,033H,OOFH,03CH,OOFH,03FHOOFH,OCOH,OOFH,0C3H,OOFH,OCCH,OOFH,OCFHOOFH,OFOH,OOFH,0F3H,OOFH,OFCH,OOFH,OFFH030H,OOOH,030H,003H,030H,OOCH,030H,OOFH030H,030H,030H,033H,030H,03CH,030H,03FH030H,OCOH,030H,0
12、C3H,030H,OCCH,030H,OCFH030H,OFOH,030H,0F3H,030H,OFCH,030H,OFFH033H,OOOH,033H,003H,033H,OOCH,033H,OOFH033H,030H,033H,033H,033H,03CH,033H,03FH033H,OCOH,033H,0C3H,033H,OCCH,033H,OCFH033H,OFOH,033H,0F3H,033H,OFCH,033H,OFFH03CH,OOOH,03CH,003H,03CH,OOCH,03CH,OOFH03CH,030H,03CH,033H,03CH,03CH,03CH,03FH03CH,OCOH,03CH,0C3H,03CH,OCCH,03CH,OCFH03CH,OFOH,03CH,0F3H,03CH,OFCH,03CH,OFFH03FH,OOOH,03FH,00