Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

x86 MASM Frame not in module

I've created a function readFileLine that should read in a line from a file, and return that line via eax. When I run my program however, an exception is thrown and I get an additional window saying the Frame is not found in module.

The function is:

; read a line from the text file using readFileChar
; receives:
;   pointer to the open file
;   pointer to the output array
;   max number of bytes to copy
; returns:
;   The number of characters read and stored in the target array
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
readFileLine PROC
    push ecx                    ; preserve ecx
    push ebx
    push edx
    mov dl, lbuffer             ; pointer to a result string
    mov ecx, 5                  ; move max line size into counter 
    L1:
        push fileptr            ; push pointer to current file location
        call readFileChar       ; read one character from the file
        cmp al, ASTERISK        ; if the character is an asterisk
        je NEXT                 ; go to next loop
        cmp al, CR              ; if the character is a c/r
        je exitLoop             ; exit the loop
        mov [edx], al           ; move the char into the open spot
        inc edx                 ; move to the next spot 
        NEXT:
            LOOP L1
        exitLoop:
            call readFileChar   ; move past the return carriage char
    mov eax, edx
    pop fileptr
    pop edx
    pop ebx
    pop ecx
    ret
readFileLine ENDP

Within that function is a helper function readFileChar:

; read a character from a file
; receives:
;   [ebp+8]  = file pointer
; returns:
;   eax = character read, or system error code if carry flag is set
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
readFileChar PROC
    push ebp                        ; save the base pointer
    mov ebp,esp                     ; base of the stack frame
    sub esp,4                       ; create a local variable for the return value
    push edx                        ; save the registers
    push ecx

    mov eax,[ebp+8]                 ; file pointer
    lea edx,[ebp-4]                 ; pointer to value read
    mov ecx,1                       ; number of chars to read
    call ReadFromFile               ; gets file handle from eax (loaded above)
    jc DONE                         ; if CF is set, leave the error code in eax
    mov eax,[ebp-4]                 ; otherwise, copy the char read from local variable

DONE:
    pop ecx                         ; restore the registers
    pop edx
    mov esp,ebp                     ; remove local var from stack 
    pop ebp
    ret 4
readFileChar ENDP

Using a debugger I can see that the crash seems to happen on the ret in readFileLine. I imagine this has got to be related to the stack, but I cannot for the life of me figure out what is causing the error to occur. Anyone have any ideas?

Comments