data segment
buf db 11h,22h,33h,44h,55h,66h,77h,88h
n db $-buf ; 你的程序中缺少这一行
min db ?
max db ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,seg data
mov ds,ax
mov dl,n
xor dh,dh
dec dx
l1:
mov cx,dx
mov si,offset buf
l2:
mov al,[si+1]
cmp al,[si]
jg next
xchg al,[si]
mov [si+1],al
next:
inc si
loop l2
dec dx
jnz l1
mov si,offset buf
mov al,[si]
mov min,al
mov al,[si+n-1]
mov max,al
mov cl,n
mov ch,0
lea si,buf
@main1:
mov al,[si]
cbw ; 将字节扩展成字
call dispaxs
inc si
loop @main1
call deletedata ; 第1次删除
call printlfcr
mov cl,n
mov ch,0
lea si,buf
@main2:
mov al,[si]
cbw
call dispaxs
inc si
loop @main2
call deletedata ; 第2次删除
call printlfcr
mov cl,n
mov ch,0
lea si,buf
@main3:
mov al,[si]
cbw
call dispaxs
inc si
loop @main3
mov ah,4ch
int 21h
;====================================
; 对排序的元素用后者顺序覆盖前者,再将计数器n减2
deletedata proc near
mov cl,n
xor ch,ch
cmp cx,2
jle @delexit
lea si,buf
dec cx
@deldata1:
mov al,[si+1]
mov [si],al
inc si
loop @deldata1
dec byte ptr n
dec byte ptr n
@delexit:
ret
deletedata endp
; ==================================
PRINTLFCR PROC NEAR
PUSH AX
PUSH DX
mov ah,2
mov dl,13
int 21h
mov dl,10
int 21h
POP DX
POP AX
RET
PRINTLFCR ENDP
;=========================================
; 将要显示的有符号数置于 ax 中
DISPAXS PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSH BP
PUSH DS
PUSH ES
PUSHF
PUSH CS
POP DS
PUSH CS
POP ES
MOV CX,6
LEA DI,DISPAXSS
@DISPAXS:
MOV BYTE PTR [DI],32
INC DI
LOOP @DISPAXS
PUSH AX
MOV DL,32
MOV AH,2
INT 21H
POP AX
MOV BYTE PTR NZS,0
MOV BYTE PTR SIGNS,0
CMP AX,0
JGE @DISPAXS0
MOV BYTE PTR SIGNS,1
NEG AX
@DISPAXS0:
PUSH AX
LEA SI,DIVARRS
LEA DI,DISPAXSS
INC DI
MOV CX,5
@DISPAXS1:
POP AX
MOV DX,0
MOV BX,[SI]
DIV BX
PUSH DX
CMP AL,0
JNE @DISPAXS2
CMP BYTE PTR NZS,1
JE @DISPAXS2
CMP CX,1
JE @DISPAXS2
MOV DL,20H
JMP @DISPAXS3
@DISPAXS2:
ADD AL,30H
MOV DL,AL
MOV BYTE PTR NZS,1
@DISPAXS3:
MOV BYTE PTR[DI],DL
INC SI
INC SI
INC DI
LOOP @DISPAXS1
POP DX
CMP BYTE PTR SIGNS,1
JNE @DISPAXS6
LEA SI,DISPAXSS
ADD SI,5
@DISPAXS4:
CMP BYTE PTR [SI],32
JE @DISPAXS5
DEC SI
JMP @DISPAXS4
@DISPAXS5:
MOV BYTE PTR [SI],'-'
@DISPAXS6:
LEA DX,DISPAXSS
MOV AH,9
INT 21H
POPF
POP ES
POP DS
POP BP
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RET
DIVARRS DW 10000,1000,100,10,1
NZS DB 0
SIGNS DB 0
DISPAXSS DB 32,32,32,32,32,32,'$'
DISPAXS ENDP
;================================================
code ends
end start