验证用户输入时,程序崩溃了,发生了什么?

时间:2015-03-08 23:39:30

标签: assembly masm validating

我正在将由数字组成的字符串转换为整数。用户输入10个字符串(一次一个字符串),字符串存储为数字。当用户在字符串中输入非数字时,程序会捕获错误并要求用户重新输入字符串。但是当程序捕获错误时,它会继续让用户输入另一个字符串,但随后它会崩溃。有什么想法吗?

;getString Macro
getString   MACRO   buffer, buffer1, buffer2

mov     edx, OFFSET buffer
call    WriteString

mov     edx, OFFSET buffer1
mov     ecx, (SIZEOF buffer1) - 1
call    ReadString
mov     buffer2, eax

ENDM
 ;---------------------------------------------------------------
 ;ReadVal Procedure - 
 ;Receives: No parameters
 ;Returns: None
 ;Preconditions: None
;---------------------------------------------------------------
    ReadVal     PROC
    push    ebp
    mov     ebp, esp
    mov     ecx, 10     ;set the outer loop

L1:
    pushad
    getString   EntNum, Numstr, [ebp + 8]
    mov     ecx, [ebp + 8]
    mov     esi, [ebp + 12]     ; points to the user's number
    mov     edi, [ebp + 24]     ; will store the user's string as a number
    cld

counter:
    lodsb
    cmp     ecx, 0
    je      continue
    cmp     al, 48
    jl      badnum
    cmp     al, 57
    jg      badnum
    jmp     store   

badnum:
    mov     edx, [ebp + 20]
    call    WriteString
    call    CrLf
    jmp     L1

store:
    sub     al, 48
    stosb
    loop    counter

    popad
    cmp     ecx, 0      ;stop the outer loop
    je      continue
    loop    L1

continue:
    pop     ebp


    RET     20
ReadVal     ENDP

1 个答案:

答案 0 :(得分:0)

无效的输入捕捉器也将寄存器推入堆栈,导致它变得不平衡。