Question
INCLUDE Irvine32.inc .DATA scores DWORD 4 DUP (5 DUP (0)) ; two-dimensional array to store scores movieSum DWORD 5 DUP (0) ; array to store
INCLUDE Irvine32.inc
.DATA scores DWORD 4 DUP (5 DUP (0)) ; two-dimensional array to store scores movieSum DWORD 5 DUP (0) ; array to store the total score for each movie movieMax DWORD ? ; variable to store the highest total score
.CODE main PROC call GetFilename ; get the name of the input file call ReadScores ; read the scores from the input file call CalculateTotals ; calculate the total score for each movie call FindMax ; find the movie with the highest total score call DisplayResults ; display the total scores and the highest-scoring movie exit ; exit the program main ENDP
GetFilename PROC mov edx, OFFSET prompt ; prompt the user for the filename call WriteString mov edx, OFFSET filename ; get the filename from the user call ReadString ret GetFilename ENDP
ReadScores PROC mov ebx, 0 ; set up a counter for the number of lines read mov esi, OFFSET scores ; point to the first element of the scores array mov edx, OFFSET filename ; point to the filename call OpenInputFile ; open the input file mov edi, OFFSET buffer ; point to a buffer to hold each line ReadLoop: mov ecx, SIZEOF buffer ; set the maximum number of characters to read call ReadLine ; read a line from the file cmp eax, 0 ; check for end of file je EndReadLoop mov ebx, [edi] ; get the movie number (ASCII code) sub ebx, 'A' ; convert to an index (0-4) mov eax, [edi+2] ; get the score mov edx, [edi+4] ; get the reviewer number mov [esi+ebx*4+edx*20], eax ; store the score in the scores array inc ebx ; increment the line counter add esi, 20 ; point to the next element of the scores array jmp ReadLoop EndReadLoop: call CloseFile ; close the input file ret ReadScores ENDP
CalculateTotals PROC mov ebx, OFFSET scores ; point to the first element of the scores array mov edx, OFFSET movieSum ; point to the first element of the movieSum array mov ecx, 5 ; set up a counter for the number of movies OuterLoop: push ecx ; save the outer loop counter mov ecx, 4 ; set up a counter for the number of reviewers InnerLoop: mov eax, [ebx] ; get the score for the current reviewer and movie add [edx], eax ; add the score to the total for the current movie add ebx, 4 ; point to the next element in the scores array add edx, 4 ; point to the next element in the movieSum array loop InnerLoop ; repeat for all reviewers pop ecx ; restore the outer loop counter add ebx, 16 ; point to the next row of the exit: ; Close the file invoke CloseHandle, hFile ; Exit the program invoke ExitProcess, 0 END main
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