哈,循环转~
程序代码:
Data segment
Msg1 db "Please input the number of students:$"
Num db 0
EnMsg db 0ah,0dh,'$'
Msg2 db "Please input the grade of each students:$"
Msg3 db "The average grade of these students is:$"
avg db 0
ascavg db 0,0,'$'
Data ends
Stack segment para stack
db 20h dup(0)
Stack ends
code segment
Assume Cs:code,Ss:stack,ds:Data
Start: mov ax,data
mov ds,ax
lea dx,Msg1
mov ah,09h
int 21h
Call Numproc
mov num,bl
lea dx,EnMsg
mov ah,09h
int 21h
lea dx,Msg2
mov ah,09h
int 21h
call Avgproc
call bta
mov ah,4ch
int 21h
Numproc proc
push ax
push cx
push dx
lea dx,EnMsg
mov ah,09h
int 21h
mov bl,0
lop1: mov ah,01h
int 21h
cmp al,0dh
jz lop2
cmp al,0dh
jl lop1
cmp al,'9'
ja lop1
sub al,30h
mov cl,al
mov al,bl
mov ch,10
mul ch
mov bl,al
add bl,cl
jmp lop1
lop2: pop dx
pop cx
pop ax
ret
Numproc endp
Avgproc proc
push ax
push cx
xor dx,dx
mov cl,num
lop3: call Numproc
xor ax,ax
mov al,bl
add ax,dx
Div num
add avg,al
xor dx,dx
mov dl,ah
sub cl,1
jnz lop3
pop ax
pop cx
ret
Avgproc endp
bta proc
push ax
push bx
xor ax,ax
mov al,avg
mov bl,10
div bl
add ah,30h
add al,30h
mov ascavg,al
mov ascavg+1,ah
lea dx,EnMsg
mov ah,09h
int 21h
lea dx,ascavg
mov ah,09h
int 21h
pop bx
pop ax
ret
bta endp
code ends
end start