-1

I'm converting an string made of numbers to an integer. The user enters 10 strings (one string at a time) and the string is stored as a number. When the user enters a non-number into the string the program catches the error and asks the user to re-enter the string. But when the program catches an error it moves on to have the user input another string but then it crashes. Any ideas why?

;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
user2466886
  • 205
  • 1
  • 3
  • 14

1 Answers1

0

The invalid input catcher was also pushing the registers to the stack causing it to become unbalanced.

user2466886
  • 205
  • 1
  • 3
  • 14