各位帮忙看看,为啥运行到call WriteFile就挂了
间谍 2003-11-28 02:08:42 .386
.model flat,stdcall
option casemap:none
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;include定义
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
include e:\masm32\include\windows.inc
include e:\masm32\include\user32.inc
include e:\masm32\include\kernel32.inc
includelib e:\masm32\lib\user32.lib
includelib e:\masm32\lib\kernel32.lib
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;数据段
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
.data?
array db 10000 dup(?) ;默认求(1-10000)素数
h_file dd ? ;文件句柄
buf db 100 dup(?) ;缓冲区
.data
g_count dd 10000 ;区间
g_bound dd 100 ;上界
suc_word dd 0 ;文件操作参数
.const
file_name db 'd:\\result.txt',0 ;存放结果的文件名
sz_finish db '计算完成',0
sz_format db ' %5d ',0
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;代码段
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
.code
start:
pushad
;初始化 array全体元素为0
mov ecx, 0
mov al, 0
@init:
cmp ecx, g_count
jg @init_finish
mov array[ecx], al
inc ecx
jmp @init
@init_finish:
;计算过程
mov eax, 1
mov array[2], 0
@find_init:
inc eax
cmp array[eax], 1
je @find_init
cmp eax, g_bound
jg @find_finish
mov cx,1
@find_begin:
push eax
inc cx
mul cx
push ax
mov ax, dx
shl eax, 8
pop ax
cmp eax, g_count
jg @go_init
mov array[eax], 1
pop eax
jmp @find_begin
@go_init:
pop eax
jmp @find_init
@find_finish:
;写入结果
push NULL
push FILE_ATTRIBUTE_NORMAL
push CREATE_ALWAYS
push NULL
push FILE_SHARE_READ
push GENERIC_WRITE
push offset file_name
call CreateFile
mov h_file, eax
mov ecx, 1
@continue:
cmp ecx, g_count
jg @finish
inc ecx
test array[ecx], 0
je @write_in
jmp @continue
@write_in:
push ecx
push offset sz_format
push offset buf
call wsprintf
push NULL
push offset suc_word
push 7
push offset buf
push h_file
运行到这附近--> call WriteFile
jmp @continue
@finish:
push h_file
call CloseHandle
popad
end start
只是一个很简单的筛选法求素数,前面的过程应该问题不大,只是输出结果的时候有些问题,请大家帮忙看看,谢谢,刚开始学汇编,有很多不懂,多多指教,也请大家多多拍砖,把我代码各个方面存在的问题都指出来。