.model small
.stack 8192
.data
counter dw 0
array db 100 dup(0)
highest db 0
lowest db 100
sum dw 0
average db 0
m1 db 13,10,'how many students are there in your class (1-100)? $'
m2 db 'score of student [$'
m3 db '] = ? $'
m4 db 'you have to enter an integer in the range of [0..100] as a score!$'
m5 db 13,10,'the highest score is $'
m6 db 13,10,'the lowest score is $'
m7 db 13,10,'the average is $'
.code
main: mov ax,@data
mov ds,ax
@@: mov dx,offset m1
call puts
call ??ulong
jc @b
test dx,dx
jnz @b
test ax,ax
jz @b
cmp ax,100 ;max ppl
ja @b
mov counter,ax
mov cx,1
mov si,offset array
lp: cmp cx,counter
ja done
mov dx,offset m2
call puts
mov ax,cx
call ?uint
mov dx,offset m3
call puts
call ??ulong
test dx,dx
jz @f
er: mov dx,offset m4
call puts
jmp lp
@@: cmp ax,100
ja er
mov [si],al
inc si
inc cx
add sum,ax
cmp al,highest
jbe @f
mov highest,al
@@: cmp al,lowest
jae lp
mov lowest,al
jmp lp
done: mov dx,offset m5
call puts
xor ax,ax
mov al,highest
call ?uint
mov dx,offset m6
call puts
xor ax,ax
mov al,lowest
call ?uint
mov dx,offset m7
call puts
xor dx,dx
mov ax,sum
div counter
call ?uint
mov ah,4ch
int 21h
putc proc
push ax
mov ah,2
int 21h
pop ax
ret
putc endp
puts proc
push ax
mov ah,9
int 21h
pop ax
ret
puts endp
??ulong proc
push bx
push cx
push si
push di
call @f
pop di
pop si
pop cx
pop bx
ret
@@: xor cx,cx
mov di,offset mydata
g_1: mov ah,8
int 21h
cmp al,13
jne g_3
mov dl,13
call putc
mov dl,10
call putc
jcxz g_2
xor ax,ax
mov si,offset mydata
g_9: mov bx,10
mul bx
mov bl,cs:[si]
sub bl,'0'
add ax,bx
adc dx,0
inc si
loop g_9
clc
ret
g_2: stc
ret
g_3: cmp al,8
jne g_4
jcxz g_1
dec cx
dec di
mov dl,8
call putc
mov dl,32
call putc
mov dl,8
call putc
jmp g_1
g_4: cmp cx,length mydata
jae g_1
cmp al,'0'
jb g_1
cmp al,'9'
ja g_1
mov dl,al
call putc
mov cs:[di],al
inc di
inc cx
jmp g_1
mydata db 11 dup (?)
??ulong endp
?uint proc ;以10进制输出ax中的无符号整数
push ax
push bx
push cx
push dx
call @f
pop dx
pop cx
pop bx
pop ax
ret
@@: or ax,ax ;是0则直接输出
jnz @f
push dx
mov dl,'0'
call putc
pop dx
ret
@@: push ax
push cx
push dx
push bx
mov bx,10
xor dx,dx
div bx
mov cx,ax
or cx,dx ;若商与余数都为0则结束递归
jz @f
push dx ;留存DX中的余数以在递归后输出
call @b ;递归
pop dx ;从最高位开始恢复余数
add dl,'0'
call putc
@@: pop bx
pop dx
pop cx
pop ax
ret
?uint endp
end main
温馨提示:答案为网友推荐,仅供参考