专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 汇编语言

怎么提高这个程序的执行速度

发布时间:2010-06-14 15:17:14 文章来源:www.iduyao.cn 采编人员:星星草
如何提高这个程序的执行速度?
程序的功能是读取硬盘上的3个文件,在申请的内存中让这3个文件异或,最后把目标文件写入磁盘。文件基本都是上百G的所以循环执行上面的操作。现在的问题是速度太慢,请帮忙看看怎么提高速度。部分源代码如下:

先申请内存
;**********************************************************************
;读指定文件到申请的虚拟内存
;**********************************************************************
  push ecx ;压入的是要循环的次数,每次循环执行8M(1024*1024*8这个值是可以变化的)的异或操作,
invoke ReadFile,@hHD1,Buffer_Point1,BUFFER_SIZE,addr dwCount,NULL  
.if eax == 0
invoke MessageBox,0,$CTA0("读1.img文件错误"),NULL,MB_ICONEXCLAMATION
.endif
invoke ReadFile,@hHD2,Buffer_Point2,BUFFER_SIZE,addr dwCount,NULL  
.if eax == 0
invoke MessageBox,0,$CTA0("读4.img文件错误"),NULL,MB_ICONEXCLAMATION
.endif
invoke ReadFile,@hHD3,Buffer_Point3,BUFFER_SIZE,addr dwCount,NULL  
.if eax == 0
invoke MessageBox,0,$CTA0("读5.img文件错误"),NULL,MB_ICONEXCLAMATION
jmp _exit
.endif 

jmp _PerXor
@@:
push ecx
invoke ReadFile,@hHD1,Buffer_Point1,BUFFER_SIZE,addr dwCount,NULL  
invoke ReadFile,@hHD2,Buffer_Point2,BUFFER_SIZE,addr dwCount,NULL  
invoke ReadFile,@hHD3,Buffer_Point3,BUFFER_SIZE,addr dwCount,NULL
;***************************************************************************
;执行异或操作
;***************************************************************************
_PerXor:
mov ecx,1024*1024*8/4 ;对应下面的loop指令中的ecx
mov edi,Buffer_Point1 ;Buffer_Point1为指针变量,值为申请内存的地址,其他类似
mov esi,Buffer_Point2
mov ebx,Buffer_Point3
@:
  mov eax,[edi]
xor eax,[esi]
xor eax,[ebx]
mov [edi],eax
add edi,4
add esi,4
add ebx,4
loop @
;写入目标文件
invoke WriteFile,@hHD4,Buffer_Point1,BUFFER_SIZE,addr dwCount,NULL
.if eax == 0
invoke MessageBox,0,$CTA0("写失败"),NULL,MB_OK
jmp _exit
.endif
pop ecx
dec ecx
cmp ecx,0
jg @B

以下是我改写成读异步的源代码,在XP上执行正确但速度没什么提高,在windows2003的操作系统上面总是写失败,不知道什么原因。读异步一直没成功。请高手指教!invoke ReadFile,@hHD1,Buffer_Point1,BUFFER_SIZE,addr dwCount,NULL  
.if eax == 0
invoke MessageBox,0,$CTA0("读1.img文件错误"),NULL,MB_ICONEXCLAMATION
.endif
invoke ReadFile,@hHD2,Buffer_Point2,BUFFER_SIZE,addr dwCount,NULL  
.if eax == 0
invoke MessageBox,0,$CTA0("读4.img文件错误"),NULL,MB_ICONEXCLAMATION
.endif
invoke ReadFile,@hHD3,Buffer_Point3,BUFFER_SIZE,addr dwCount,NULL  
.if eax == 0
invoke MessageBox,0,$CTA0("读5.img文件错误"),NULL,MB_ICONEXCLAMATION
jmp _exit
.endif 
mov @overlapped.loffset,0
mov @overlapped.OffsetHigh,0
cld
jmp _PerXor
@@:
push ecx
add @overlapped.loffset,BUFFER_SIZE
mov @overlapped.OffsetHigh,0
invoke ReadFile,@hHD1,Buffer_Point1,BUFFER_SIZE,addr dwCount,NULL  
invoke ReadFile,@hHD2,Buffer_Point2,BUFFER_SIZE,addr dwCount,NULL  
invoke ReadFile,@hHD3,Buffer_Point3,BUFFER_SIZE,addr dwCount,NULL
;***************************************************************************
;执行异或操作
;***************************************************************************
_PerXor:
mov ecx,1024*1024*64/4 ;对应下面的loop指令中的ecx
mov edi,Buffer_Point1
mov esi,Buffer_Point2
mov ebx,Buffer_Point3
@:
mov eax,[edi]
xor eax,[esi]
xor eax,[ebx]
mov [edi],eax
add edi,4
add esi,4
add ebx,4
loop @
;写入目标文件
invoke WriteFile,@hHD4,Buffer_Point1,BUFFER_SIZE,addr dwCount,addr @overlapped
.if eax == 0
invoke MessageBox,0,$CTA0("写失败"),NULL,MB_OK
jmp _exit
.endif
pop ecx
dec ecx
cmp ecx,0
jg @B

------解决方案--------------------
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: