新手求指导,汇编实现数组的输入与输出
源代码如下,编译连接都没问题,但是运行的时候内存出错啦。。。用windbg也看不出。。。
源代码如下
; author: FrozenMoon
; date: 2011.5.6
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
include io.h ; header file for input/output
cr equ 0dh ; carriage return character
Lf equ 0ah ; line feed
maxlen equ 100 ;数组最大长度
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
prompt1 BYTE 'Now Init the Array ',cr,Lf,Lf,0
prompt2 BYTE 'please input a number :',0
prompt3 BYTE 'please input the length of Array :',0
number BYTE 16 DUP (?)
Array DWORD maxlen DUP(?)
Len DWORD ?
Value BYTE 11 DUP(?) ,0
Find BYTE cr,Lf,Lf,'find if!!',0
NoFind BYTE cr,Lf,Lf,'can not find if!',0
.CODE
; start of main program code
showArray PROC NEAR32
push ebp ; establish stack frame
mov ebp,esp
pushad
pushf ; save flags
mov ebx,[ebp+12] ;数组首地址
mov ecx,[ebp+8] ;数组长度
forcount:
dtoa Value,[ebx]
output Value
add ebx,4
loop forcount ;
endfor :
popf ; restore flags
popad
pop ebp ; restore EBP
ret ; return
showArray ENDP
_start:
output prompt1
Safe: output prompt3
input number,16
atod number
cmp eax,maxlen
jg Safe ; 超过范围再次输入
mov len,eax ;输入数组长度
lea ebx,Array ;取数组首地址
mov ecx,len
forArray:
output prompt2
input number,16
atod number
mov [ebx],eax
add ebx,4
loop forArray ;循环
lea ebx,Array ;取数组首地址
push ebx ;压入数组首地址
mov edx,len
push edx ;压入数组长度
call showArray show the Array
add esp,8
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code
调试的时候我把大多数的语句都注释掉后,只留简单的输出字符串操作就没错。。。实在找不出错在哪了。。。