显示学生名次表,有点问题。请高手帮修改一下
从键盘接收输入的一个班的学生成绩,并存放于50字grade数组中,其中grade+i保存学号为i+1的学生成绩。然后根据grade中的学生成绩,把学生名次填入50字rank字数组中,其中 rank+i的内容是学号为i+1学生的名次。再按学号顺序把名次从终端上显示出来。(输入学生个数<=50,可以不定)DATAS SEGMENT
;此处输入数据段代码
grade dw 50 dup(?)
rank dw 50 dup(?)
count dw 0
message1 db 'Input the Grades :',0DH,0AH,'$'
errorl db 'Error',0DH,0AH,'$'
message2 db 'The Rank is :',0aH,0DH,'$'
me db 2 dup(?)
DATAS ENDS
;***************************************************************
CODES SEGMENT
main proc far
ASSUME CS:CODES,DS:DATAS
START:
push dx
sub ax,ax
push ax
MOV AX,DATAS
MOV DS,AX
;此处输入代码段代码
call input
call rankp
call output
ret
main endp
;****************************************************************
input proc near
lea dx,message1
mov ah,09
int 21H
mov si,0
mov count,0
enter:
call decibin
inc count
cmp dl,','
je store
cmp dl,13
je exit2
jne error
store:
mov grade[si],bx
add si,2
jmp enter
error:
lea dx,errorl
mov ah,09H
int 21H
exit2:
mov grade[si],bx
call crlf
ret
input endp
;*********************************************************
crlf proc near
mov dl,0AH
mov ah,02H
int 21H
mov dl,0DH
mov ah,02H
int 21H
ret
crlf endp
;***************************************************
decibin proc near
mov bx,0
newchar:
mov ah,01
int 21H
mov dl,al
sub al,30H
jl exitl
cmp al,9D
jg exitl
cbw
xchg ax,bx
mov cx,10D
mul cx
xchg ax,bx
add bx,ax
jmp newchar
exitl: ret
decibin endp
;********************************************************
rankp proc near
mov di,count
mov bx,0
loopl:
mov ax,grade[bx]
mov word ptr rank[bx],0
mov cx,count
lea si,grade
next:
cmp ax,[si]
jg nocount
inc word ptr rank[bx]
nocount:
add si,2
loop next
add bx,2
dec di
jnc loopl
ret
rankp endp
;************************************
output proc near
lea dx,message2
mov ah,09H
int 21H
mov si,0
mov di,count
nextl:
mov bx,rank[si]
call binidec
mov dl,','
mov ah,02
int 21H
add si,2
dec di
jnz nextl
call crlf
ret
output endp
;****************************************
binidec proc near
push bx
push cx
push si
push di
mov cx,100D
call dec_div
mov cx,10D
call dec_div
mov cx,1D
call dec_div
pop di
pop si
pop cx
pop bx
ret
binidec endp
dec_div proc near
mov ax,bx
mov dx,0
div cx
mov bx,dx
mov dl,al
add dl,30H
mov ah,02H
int 21H
ret
dec_div endp
MOV AH,4CH
INT 21H
CODES ENDS
END START