实现学生成绩排序
data segment
M1 db "num:$"
M2 db "name:$"
M3 db "score:$"
EM db 13,10,'$'
student struct
sname db 10,?,10 dup(?)
score db 4,?,4 dup(?)
student ends
m dw 500 dup(?)
num dw 0
i dw ?
j dw ?
stus student 500 dup({})
data ends
stack segment para stack
db 40 dup(0)
stack ends
code segment
assume cs:code,ss:stack,ds:data
start:mov ax,data
mov ds,ax
lea dx,M1
mov ah,09h
int 21h
call inone
mov num,dx
lea dx,EM
mov ah,09h
int 21h
;call inone
;mov num,dx
;call init
call input
call sort
mov ah,4ch
int 21h
inone proc
push ax
push bx
push cx
xor dx,dx
lop: mov ah,01h
int 21h
cmp al,0dh
jz extp1
and al,0fh
mov cl,al
mov ax,dx
mov bx,10
mul bx
mov dx,ax
mov ch,0
add dx,cx
jmp lop
extp1:pop cx
pop bx
pop ax
ret
inone endp
input proc
push bx
push cx
push si
;push bx
xor bx,bx
mov si,0
mov cx,16
lop:cmp bx,num
jz extp2
lea dx,M2
mov ah,09h
int 21h
lea dx,stus[si]
mov ah,0ah
int 21h
lea dx,EM
mov ah,09h
int 21h
lea dx,M3
mov ah,09h
int 21h
lea dx,stus[si+12]
mov ah,0ah
int 21h
lea dx,EM
mov ah,09h
int 21h
mov m[bx],bx
add si,cx
inc bx
jmp lop
extp2:;pop bx
pop si
pop cx
pop bx
ret
input endp
sort proc
push ax
push bx
push cx
push dx
pop si
pop di
xor cx,cx
xor dx,dx
xor ax,ax
xor bx,bx
mov bx,16
lea si,stus[12]
lea di,stus[12]
lop2:mov dx,cx
cmp cx,num
jz extp3
lop3:cmp dx,num
jz next2
mov i,cx
mov j,dx
call comp
add di,bx
inc dx
jmp lop3
next2:add si,bx
inc cx
jmp lop2
extp3:pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
sort endp
comp proc
;push ax
;push bx
push dx
push cx
mov ax,0
mov bx,0
mov dx,0
inc si
inc di
mov ax,[si]
mov bx,[di]
dec si
dec di
cmp ax,bx
ja a
jb b
a:mov cx,bx
jmp res
b:mov cx,ax
jmp res
res:repz cmpsb