Question
This program is in MASM using Irvine 32 bit library. I have it written, but I'm getting a syntax error that I can't resolve. Can
This program is in MASM using Irvine 32 bit library. I have it written, but I'm getting a syntax error that I can't resolve. Can anyone please help?
INCLUDE Irvine32.inc
.data inFileName byte "grades.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 carr 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
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, the exception error is here
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
text file:
300 taylor 287 Thomas 197 brown 250 lee 273 rReynolds 282 lion 192 mack 265 lewis 176 marshall 277 moto 262 vey 286 knocktosee 291 toSha 283 bozo 203 WayOut 279 ace 258 aceAgain 245 boyanze 235 thomson 188 onmore 265 ilyed 288 mark 276 beth 166 Timmy 199 cece 209 superman 293 batman 292 GreenHornit 290 ray 229 kidSid 200 kidSyd 188 lastone 245
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started