编写一个比赛得分程序。共有7 个评委,按百分制打分,计分
原则是去掉一个最高分和一个最低分,求平均值。要求:
DATAS SEGMENT
;此处输入数据段代码
inputMsg db 'please input$'
errMsg db 0ah, 0dh, 'please input 0-100$'
finalMsg db 0ah, 0dh, 'the score is $'
score DB 30H
DB 0
DB 30H DUP('$')
realScore dw 0
minScore dw 100
maxScore dw 0
count dw 0
DATAS ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
;此处输入代码段代码
mov ax, 0
mov count, ax
mov maxScore, ax
mov ax, 100
mov minScore, ax
mov cx, 7
input:
mov realScore, 0
mov dx, cx
add dx, '0'
mov ah, 02h
int 21h
lea dx, inputMsg
mov ah, 09h
int 21h
lea dx, score
mov ah, 0ah
int 21h
MOV DX,0AH;回车换行
MOV AH,02H
INT 21H
MOV DX,0DH
MOV AH,02H
INT 21H
call checkInvalid
loop input
jmp output
checkInvalid proc
push cx
mov al, score[1]
cmp al, 3
ja error
mov si, 2
mov cl, score[1]
funcCheckInvalidLop:
mov ax, 0
mov al, score[si]
sub al, '0'
cmp al, 0
jb error
cmp al, 9
ja error
push ax
mov ax, 10
mul realScore
mov realScore, ax
pop ax
add realScore, ax
inc si
loop funcCheckInvalidLop
mov dx, 0
mov ax, realScore
cmp ax, 100
ja error
add count, ax
cmp ax, minScore
ja checkMax
mov minScore, ax
checkMax:
cmp ax, maxScore
jb funcCheckInvalidRet
mov maxScore, ax
funcCheckInvalidRet:
pop cx
ret
checkInvalid endp
output:
lea dx, finalMsg
mov ah, 09h
int 21h
mov dx, 0
mov ax, count
sub ax, minScore
sub ax, maxScore
mov bx, 5
div bx
;AX商,DX余数
push dx
mov bx, 10
mov cl, 0
funcOutputDivLop:
mov dx, 0
div bx
add dl, '0'
push dx
inc cl
cmp ax, 0
jne funcOutputDivLop
funcOutputOutLop:
pop dx
mov ah, 02h
int 21h
loop funcOutputOutLop
mov dx, '.'
int 21h
pop dx
sal dx, 1
add dx, '0'
int 21h
jmp exit
error:
lea dx, errMsg
mov ah, 09h
int 21h
exit:
MOV AH,4CH
INT 21H
CODES ENDS
END START