I just wrote this program in assembly (IA-32, MASM) and I am struggling to fix the issue that I am facing. The program compiles and I can enter my name and one singular value, then the program crashes and says “Frame not in module. The current stack frame was not found in a loaded module. Source cannot be shown for this location”. It also says “Exception thrown at 0x0019FFDC in Project.exe: 0xC0000005: Access violation executing location 0x0019FFDC” as the error. I have tried everything I can think of but I have no idea what to do.
I have tried messing around with pushing random values to the stack but it does not seem to effect anything. Here is the code for reference.
INCLUDE Irvine32.inc
.data
; All of the necessary strings (prompts, operators, etc) stored as bytes
promptPt1 BYTE "We will be accumulating user-input negative integers between the specified bounds, then displaying", 0
promptPt2 BYTE "statistics of the input values including minimum, maximum, and average values values, total sum,", 0
promptPt3 BYTE "and total number of valid inputs.", 0
promptName BYTE "What is your name? ", 0
promptHello BYTE "Hello there, ", 0
promptNumRange BYTE "Please enter numbers in [-200, -100] or [-50, -1].", 0
promptNegativeNum BYTE "Enter a non-negative number when you are finished, and input stats will be shown.", 0
promptEnterNum BYTE "Enter number: ", 0
promptInvalid BYTE "This is not a number we're looking for (Invalid Input)!", 0
promptMaxValid BYTE "The maximum valid number is ", 0
promptMinValid BYTE "The minimum valid number is ", 0
promptSumValid BYTE "The sum of your valid numbers is ", 0
promptAvg BYTE "The rounded average is ", 0
goodbye BYTE "Thanks for using Integer Acumulator, goodbye.", 0
youEntered BYTE "You entered ", 0
validNumbers BYTE " valid numbers.", 0
; (insert variable definitions here)
userName BYTE 20 DUP(?)
userEntry SDWORD ?
numCount SDWORD 1
numForAverage SDWORD 1
maxNum SDWORD -200 ; min and max set to -200 initially for testing
minNum SDWORD -200
sum SDWORD 0
average SDWORD 0
.code
main PROC
call introduction
call getNums
call calculate
call results
MOV EDX, OFFSET goodbye
call WriteString
call CrLf
; (insert executable instructions here)
Invoke ExitProcess,0 ; exit to operating system
main ENDP
introduction PROC
MOV EDX, OFFSET promptPt1
call WriteString
call CrLf
MOV EDX, OFFSET promptPt2
call WriteString
call CrLf
MOV EDX, OFFSET promptPt3
call WriteString
call CrLf
MOV EDX, OFFSET promptName
call WriteString
MOV EDX, OFFSET userName
MOV ECX, length userName-1
call ReadString
call CrLf
MOV EDX, OFFSET promptHello
call WriteString
MOV EDX, OFFSET userName
call WriteString
call CrLf
call CrLf
MOV EDX, OFFSET promptNumRange
call WriteString
call CrLf
MOV EDX, OFFSET promptNegativeNum
call WriteString
call CrLf
ret
introduction ENDP
getNums PROC
MOV EAX, 0
; use stack to get all the values from the user stored (USE IN WHILE LOOP)
numLoop:
MOV EAX, userEntry
MOV EDX, OFFSET promptEnterNum
call WriteString
call ReadDec
MOV userEntry, EAX
call checkValidity
CMP EAX, 0
JNS continueEnd
PUSH EAX
CMP EAX, 0
JNS numLoop
continueEnd:
MOV EAX, numCount
MOV numForAverage, EAX
ret
getNums ENDP
checkValidity PROC
; if the number entered is not between -200 and -100 or -50 and -1, jump to invalidEntry
CMP EAX, -1
JG continueFunc
CMP EAX, -50
INC numCount
JGE continueFunc
CMP EAX, -200
JL invalidEntry
CMP EAX, -100
JG checkMidRange
INC numCount
JL continueFunc
checkMidRange:
CMP EAX, -50
JL invalidEntry
invalidEntry:
MOV EDX, OFFSET promptInvalid
call WriteString
call CrLf
JMP continueFunc
continueFunc:
ret
checkValidity ENDP
calculate PROC
comparing:
POP EAX
POP EBX
ADD sum, EAX
CMP numCount, 1
JL continueFunc
CMP EAX, EBX
JGE greater
JLE less
greater:
MOV maxNum, EAX
DEC numCount
JMP comparing
less:
MOV minNum, EAX
DEC numCount
JMP comparing
continueFunc:
MOV EDX, 0
MOV EAX, sum
MOV average, EAX
MOV EAX, average
MOV EBX, numForAverage
DIV EBX
ret
calculate ENDP
results PROC
MOV EDX, OFFSET promptMaxValid
call WriteString
MOV EAX, maxNum
call WriteDec
call CrLf
MOV EDX, OFFSET promptMinValid
call WriteString
MOV EAX, minNum
call WriteDec
call CrLf
MOV EDX, OFFSET promptSumValid
call WriteString
MOV EAX, sum
call WriteDec
call CrLf
MOV EDX, OFFSET promptAvg
call WriteString
MOV EAX, average
call WriteDec
call CrLf
ret
results ENDP
END main