📄 zhang5.asm
字号:
data segment
table db 20 dup(?)
table1 db 20 dup(?)
count equ ($-table)/2
max db ?
min db ?
mode db ?
mesg db 'Error! You have input a wrong number.',0ah,0dh
db '$'
data ends
;----------------------------------------------
stack segment para stack 'stack'
dw 100 dup(?)
stack ends
;----------------------------------------------
code segment
assume cs:code,ds:data,ss:stack
main proc far
start: push ds
mov ax,0
push ax
mov ax,data
mov ds,ax
;----------------------------------------------
mov cx,20
mov di,offset table
mov si,offset table1
again:
call keydtob
call crlf
mov byte ptr[di],dh
mov byte ptr[si],dh
inc di
inc si
dec cx
jz next1
jmp again
next1:
mov bl,1
again0: cmp bl,0
jz next2
xor bl,bl
mov cx,count
dec cx
mov si,count-1
again1: mov al,table1[si]
cmp al,table1[si-1]
jae unch
exch: xchg table1[si-1],al
mov table1[si],al
mov bl,1
unch: dec si
loop again1
jmp again0
;----------------------------------------------
next2:
mov si,count-1
mov al,table1[si]
mov max,al
mov si,offset table1
mov al,byte ptr[si]
mov min,al
disp1: mov bl,max
call bintodec
call crlf
mov bl,min
call bintodec
call crlf
call crlf
;----------------------------------------------
mov di,20
mov si,offset table
disp2: mov bl,byte ptr[si]
call bintodec
inc si
dec di
jnz disp2
;----------------------------------------------
call crlf
mov si,20
mov di,offset table1
disp3: mov bl,byte ptr[di]
call bintodec
inc di
dec si
jnz disp3
;----------------------------------------------
exit: ret
main endp
;----------------------------------------------
bintodec proc near
mov cl,100
call dec_div
mov cl,10
call dec_div
mov cl,1
call dec_div
ret
;----------------------------------------------
dec_div proc near
push ax
mov al,bl
mov ah,0
div cl
mov bl,ah
mov dl,al
;----------------------------------------------
add dl,30h
mov ah,02h
int 21h
pop ax
ret
dec_div endp
;----------------------------------------------
keydtob proc near
push ax
push bx
push cx
keyin1: mov dl,3
mov bx,0
mov dh,0
keyin:
mov ah,01h
int 21h
sub al,30h
jl exit1
cmp al,9
jg exit1
mov ah,0
xchg al,bl
mov cl,10
mul cl
cmp ah,0
jg exit1
xchg al,bl
add bl,al
jc exit1
mov dh,bl
dec dl
jnz keyin
jmp next3
exit1: call crlf
mov dx,offset mesg
mov ah,09h
int 21h
call crlf
jmp keyin1
next3: pop cx
pop bx
pop ax
ret
keydtob endp
;----------------------------------------------
crlf proc near
push dx
push ax
mov dl,0dh
mov ah,02h
int 21h
mov dl,0ah
mov ah,02h
int 21h
pop ax
pop dx
ret
crlf endp
;----------------------------------------------
code ends
;----------------------------------------------
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -