Exception thrown at 0x00403705 in Project.exe: 0xC0000005: Access violation writing location 0x6F742074, what am I doing wrong?

-4

I'm getting an exception error in this program, I bolded the mov[esi], al; move first name char into names array where the exception happens.

I don't know what to do to fix it.

    INCLUDE Irvine32.inc


.data

inFileName byte "input.txt", 0

outFileName byte "results.txt", 0

IFD dword ?

OFD dword ?

head dword LL

LL dword 300 dup(? )

maxGrade dword ?

name_ equ 0

grade equ 4

linky equ 8

arg equ 4

lineIn byte 500 dup(? )

names byte 500 dup(? )

myAry byte 16 dup(? )

endl byte 0dh, 0ah, 0

tab_ byte 09h, 0

lineInAddr dword ?

currentNameAddr dword ?

namesAddr dword names

temp dword ll

tempAddr dword temp

prev dword ?

targetGrade dword ?

.code

main proc

lea edx, outFileName

call CreateOutputFile

mov OFD, eax; open output file

lea edx, inFileName

call OpenInputFile

mov IFD, eax; open input file

lea edx, lineIn

mov ecx, 500; bytes to read in

mov eax, IFD

call ReadFromFile; read infile

lea edi, lineIn; edi points to first byte of input

call getGrade

lea esi, myAry

call atoi

mov maxGrade, eax; get max grade

mov eax, head

mov temp, eax

mainLoop :

call getName

lea esi, myAry

mov ch, 16

call blankout; clear out esi

call getGrade

lea esi, myAry

call atoi

mov targetGrade, eax; get target grade

call insertNode

mov eax, 0

mov al, [edi]

cmp al, NULL

jne mainLoop

call printLL

exit
main endp

insertNode proc

mov esi, head; esi points to head - current node

mov prev, NULL; prev is null

insertNodeLoop :

mov eax, NULL

cmp linky[esi], eax

je leaveInsertNodeLoop; check if current is null

mov eax, targetGrade

cmp grade[esi], eax

jle leaveInsertNodeLoop; check if current grade is greater than target grade

mov prev, esi; prev equals current

lea esi, linky[esi]; current = current->linky

jmp insertNodeLoop

leaveInsertNodeLoop :

mov lineInAddr, edi; save line in address

mov edi, temp; edi points to temp node

mov eax, currentNameAddr

mov name_[edi], eax; move name into temp

mov eax, targetGrade

mov grade[edi], eax; move grade into temp

mov linky[edi], esi; move current address into temp

mov eax, NULL

cmp prev, eax; cmp prev, eax

jne updatePrev; check if we need to update prev

mov eax, edi

mov head, eax; head equals temp

jmp leaveInsertNode

updatePrev :

mov eax, edi; move temp into eax

mov prev + linky, eax; prev->linky = temp   

mov linky[prev], eax

leaveInsertNode :

mov edi, lineInAddr; restore linein address

add esi, 12; esi points to next node

mov temp, esi; temp points to next node

ret; 4

insertNode endp

printLL proc

mov edi, head

nextNode :

mov esi, name_[edi]

call fileOut

lea esi, tab_

call fileOut; print tab

mov eax, grade[edi]

mov ebx, 100

imul ebx

idiv maxGrade; convert grade

call itoa

call fileOut; print grade

lea esi, myAry

mov ch, 32

call blankout; clear out esi

lea esi, endl

call fileOut; print new line

mov edi, linky[edi]

cmp edi, NULL

jne nextNode

ret

printLL endp

fileOut proc

mov bl, NULL

nextChar :

mov eax, OFD

mov edx, esi

mov ecx, 1

call WriteToFile

add esi, 1

cmp[esi], bl; check if null

jne nextChar

ret

fileOut endp

getGrade proc

lea esi, myAry

mov ebx, 0

nextDigit:

mov bl, [edi]

mov[esi], bl

inc edi

inc esi

mov bl, 0dh

cmp[edi], bl; check for char ret

jne nextDigit

add edi, 2; edi points to next good char in lineIn

ret

getGrade endp

getName proc

mov esi, namesAddr; esi points to next empty slot of names array

mov currentNameAddr, esi; save address of current name

mov eax, 0

mov al, [edi]; move first name char into al

and al, 223; convert to upper case

mov[esi], al; move first name char into names array, **the exception error is right here** 

getNameLoop:

inc esi

inc edi

mov al, ' '

cmp[edi], al

je leaveGetNameLoop

mov eax, 0

mov al, [edi]

mov[esi], al; move name char into names array

jmp getNameLoop

leaveGetNameLoop :

inc esi

inc edi; edi points to next good char in lineIn

mov namesAddr, esi

ret

getName endp

atoi proc

mov eax, 0

nextDigit:

mov edx, 0

mov dl, [esi]

cmp dl, '0'

jl  outOfHere

cmp dl, '9'

jg outOfHere; check if char is digit

add dl, -'0'

imul eax, 10

add eax, edx

inc esi

jmp nextDigit

outOfHere :

ret

atoi endp

itoa proc

itoaLoop :

mov edx, 0

mov ecx, 10

idiv ecx

add dl, '0'

dec esi

mov[esi], dl

cmp eax, 0

jne itoaLoop

ret

itoa endp

blankout proc

blnkLoop :

mov cl, ' '

mov[esi], cl

inc esi

dec ch

cmp ch, 0

jne blnkLoop

ret

blankout endp

end main
assembly
masm
irvine32
asked on Stack Overflow Jul 3, 2020 by Wildcat75 • edited Jul 3, 2020 by Peter Cordes

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0