📄 st.asm
字号:
stack segment para stack 'stack'
db 80 dup (?)
stack ends
;-----------------------------------------
dseg segment para 'data'
crlf db 13,10,'$'
prompt db ' , ','$'
highmsg db ' The highest score is: ','$'
lowmsg db ' The lowest score is: ','$'
startmsg db ' Pleae input score: ','$'
dismsg db ' The Scores is : ','$'
dsc db 0,0,0,0,0,0,0
outputmsg db ' The last score is: ','$'
score db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
dseg ends
;------------------------------------------
cseg segment para 'code'
begin proc far
assume cs:cseg,ds:dseg,ss:stack
push ds
sub ax,ax
push ax
mov ax,dseg
mov ds,ax
;========start
lea dx,startmsg
mov ah,09h
int 21h
lea dx,crlf
int 21h
call input
lea dx,crlf
mov ah,09h
int 21h
call changsc
call index
;========display high & low
; high
mov al,dsc[6]
call btobcd
mov bl,ah
lea dx,highmsg
mov ah,09h
int 21h
mov dl,al
mov ah,02
int 21h
mov dl,bl
mov ah,02
int 21h
lea dx,crlf
mov ah,09h
int 21h
;====low
mov al,dsc
call btobcd
mov bl,ah
lea dx,lowmsg
mov ah,09h
int 21h
mov dl,al
mov ah,02
int 21h
mov dl,bl
mov ah,02
int 21h
lea dx,crlf
mov ah,09h
int 21h
;=======average
mov cx,5
lea bx,dsc
inc bx
mov al,0
ave:
add al,[bx]
inc bx
loop ave
;======display the last score
sub ah,ah
mov bl,5
div bl
call btobcd
mov bl,ah
lea dx,outputmsg
mov ah,09h
int 21h
mov dl,al
mov ah,02
int 21h
mov dl,bl
mov ah,02
int 21h
lea dx,crlf
int 21h
ret
begin endp
;=====================================================
input proc near
lea dx,prompt
lea bx,score
mov cx,07
rev:
mov ah,1
int 21h
mov [bx+1],al ; 读入一个字节(十位数)
int 21h
mov [bx],al ;读入一个字节(个位数)
add bx,2
mov ah,09 ;输出一个分隔符逗号
int 21h
loop rev
lea dx,crlf
mov ah,09
int 21h
ret
input endp
tran proc near ;将BCD码转换为二进制
and ax,0f0fh
mov bl,ah
mov cl,3
shl ah,cl
mov cl,1
shl bl,cl
add ah,bl
add al,ah
ret
tran endp
changsc proc near ;将七个数转换为二进制
lea di,dsc
lea bx,score
mov cx,07
loop1:
mov al,[bx]
inc bx
mov ah,[bx]
inc bx
call tran
mov [di],al
inc di
loop loop1
ret
changsc endp
index proc near ;对DSC由小到大排序,用选择法
mov cx,06
lea bx,dsc
loop2:
mov al,[bx]
mov di,bx
push cx
push bx
loop3:
inc bx
cmp al,[bx]
jle nochg
mov al,[bx]
mov di,bx
nochg:
loop loop3
pop bx
pop cx
cmp di,bx
je noexch
mov ah,[bx]
mov [di],ah
mov [bx],al
noexch:
inc bx
loop loop2
ret
index endp
btobcd proc near ;将二进制转换为非压缩BCD码
sub ah,ah
mov dl,10
div dl
add al,30h ;为十位数
add ah,30h ;为个位数
ret
btobcd endp
cseg ends
end begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -