-1

我正在将由数字组成的字符串转换为整数。用户输入 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
4

1 回答 1

0

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

于 2015-03-09T00:01:45.103 回答