Q:

calculating students avg using loop

This program should calculate the avg grades of students. 
I'm using a loop for the user to input 5 grades.
I tried to keep the div part outside the loop, but it did not work.
I had to put it inside the loop although logically doesn't make since and it always prints 1.
here is the code:
include irvine32.inc

; Write a MASM program that calculates the avg grade of a student(Five grades are inputted by the user).

.data

mesg byte "     *********This program calculates average grades of students *********", 0dh, 0ah, 0
mesg1 byte "Enter 5 grades: ", 0dh, 0ah, 0
mesg2 byte "The average grade is: ", 0dh, 0ah, 0

grade1 dword ?
grade2 dword ?
grade3 dword ?
grade4 dword ?
grade5 dword ?

.code
main proc

mov eax, 0

mov edx, OFFSET mesg
call writestring

mov edx, OFFSET mesg1
call writestring

mov ecx, 5

myLoop :

call readint
mov grade1, eax
call readint
mov grade2, eax
call readint
mov grade3, eax
call readint
mov grade4, eax
call readint
mov grade5, eax

add eax, grade1
add eax, grade2
add eax, grade3
add eax, grade4
mov grade5, eax

call writeint

call dumpregs

    LOOP myLoop

mov edx, OFFSET mesg2
call writestring

mov eax, grade5
mov cl, 5
sub edx, edx
div cl

call writeint
call dumpregs

exit
main endp
end main

calculating avg, with the div inside the loop:
include irvine32.inc

; Write a MASM program that calculates the avg grade of a student(Five grades are inputted by the user).

.data

mesg byte "     *********This program calculates average grades of students *********", 0dh, 0ah, 0
mesg1 byte "Enter 5 grades: ", 0dh, 0ah, 0
mesg2 byte "The average grade is: ", 0dh, 0ah, 0

grade1 dword ?
grade2 dword ?
grade3 dword ?
grade4 dword ?
grade5 dword ?

.code
main proc

    mov eax, 0

    mov edx, OFFSET mesg
    call writestring

    mov edx, OFFSET mesg1
    call writestring

    mov ecx, 5

myLoop:
    call readint
    mov grade1, eax
    call readint
    mov grade2, eax
    call readint
    mov grade3, eax
    call readint
    mov grade4, eax
    call readint
    mov grade5, eax

    add eax, grade1
    add eax, grade2
    add eax, grade3
    add eax, grade4
    mov grade5, eax

    call writeint

    call dumpregs

    mov edx, OFFSET mesg2
    call writestring

    mov eax, grade5
    mov ebx, 5
    sub edx, edx
    div ebx

    call writeint
    call dumpregs

    LOOP myLoop

    exit
main endp
end main

A:

add eax, grade1
add eax, grade2
add eax, grade3
add eax, grade4
mov grade5, eax

The code above has 2 problems. You didn't clear the EAX register at the start and you forgot to add in the 5th grade. Correct it like:
mov eax, grade1  <-- MOV = start with a clean EAX
add eax, grade2
add eax, grade3
add eax, grade4
add eax, grade5
mov grade5, eax

mov eax, grade5
mov cl, 5
sub edx, edx
div cl

To calculate the average you want to divide the dword in EAX by 5, but by writing div cl you only divide the word in AX. Best use the following:
mov eax, grade5
mov ecx, 5
sub edx, edx    ;Will divide EDX:EAX by ECX
div ecx         ;Quotient in EAX

I had to put it inside the loop although logically doesn't make sense

It does make sense when inputting 5 grades each for 5 students.
What doesn't make sense is the myLoop loop on the 1st program. It'll only give an average for the last set of 5 grades!

