有高手在吗,帮忙看个程序,结果总是出错
从键盘接收六个16进制数(OH~FFFH)按降序排序输出,输出时为10进制数
DATA SEGMENT
BUF DB 8
DB ?
DB 8 DUP (?)
CHANGE DB 5 DUP(?)
RESULT DW 10 DUP(?)
DISP DB 10 DUP(?)
SIGN DB ?
HELP1 DB'ENTER THE NUMBER :$'
HELP2 DB'THE RESULT IS:$'
DATA ENDS
STACK SEGMENT PARA STACK 'STACK'
DB 100 DUP(8)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK
START PROC FAR
PUSH DS
MOV AX,0
PUSH AX
MOV AX,DATA
MOV DS,AX
MOV ES,AX
MOV DX,OFFSET HELP1
MOV AH,09H
INT 21H
MOV BX,OFFSET RESULT
MOV CX,10
AGAIN: PUSH CX
MOV DL,0AH
MOV AH,2
INT 21H
MOV DL,0DH
MOV AH,2
INT 21H
CALL GETD
MOV [BX],CX
INC BX
INC BX
POP CX
LOOP AGAIN
CALL CAMP
MOV DL,0AH
MOV AH,2
INT 21H
MOV DL,0DH
MOV AH,2
INT 21H
MOV DX,OFFSET HELP2
MOV AH,09H
INT 21H
MOV CX,10
MOV SI,OFFSET RESULT
LOP4: PUSH CX
MOV CX,[SI]
CALL PTDN
INC SI
INC SI
POP CX
LOOP LOP4
RET
START ENDP
GETD PROC
PUSH AX
PUSH BX
PUSH DX
PUSH SI
PUSH DI
MOV SI,OFFSET BUF+1
MOV DI,OFFSET CHANGE
PUSH DI
MOV DX,OFFSET BUF
MOV AH,10
INT 21H
MOV BL,[SI]
DEC BL
INC SI
MOV AL,0
MOV SIGN,AL
MOV AL,[SI]
CMP AL,'+'
JZ NEXT1
MOV AL,1
MOV SIGN,AL
NEXT1:PUSH BX
NEXT2:INC SI
MOV AL,[SI]
AND AL,0FH
MOV [DI],AL
INC DI
DEC BL
JNZ NEXT2
POP BX
POP DI
MOV CX,0
AG1: PUSH BX
ADD CX,CX
MOV BX,CX
ADD CX,CX
ADD CX,CX
ADD CX,BX
MOV BL,[DI]
MOV BH,0
INC DI
ADD CX,BX
POP BX
DEC BL
JNE AG1
MOV AL,SIGN
OR AL,AL
JZ DONE
NEG CX
DONE: POP DI
POP SI
POP DX
POP BX
POP AX
RET
GETD ENDP
CAMP PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
MOV DX,9
LOP1: MOV SI,OFFSET RESULT
MOV CX,DX
MOV BL,0
LOP2: MOV AX,[SI]
CMP AX,[SI+2]
JGE LOP3
XCHG AX, [SI+2]
MOV [SI] ,AX
OR BL,1
LOP3: INC SI
INC SI
DEC CX
JNZ LOP2
AND BL,BL
JZ EXIT
DEC DX
JNZ LOP1
EXIT: POP SI
POP DX
POP CX
POP BX
POP AX
RET
CAMP ENDP
PTDN PROC
PUSH AX
PUSH BX
PUSH DX
PUSH SI
MOV BX,OFFSET DISP
MOV AL,20H
MOV [BX],AL
INC BX
MOV AL,CH
OR AL,AL
JNS PLUS
NEG CX
MOV AL,'-'
MOV [BX],AL
JMP GOON
PLUS: MOV AL,'+'
MOV [BX],AL
GOON: MOV AL,0
PUSH AX
INC BX
MOV SI,10000
CALL QUAN
MOV SI,1000
CALL QUAN
MOV SI,100
CALL QUAN
MOV SI,10
CALL QUAN
POP AX
MOV AL,30H
ADD AL,CL
MOV [BX],AL
INC BX
MOV AL,'$'
MOV [BX],AL
INC BX
MOV AL,0AH
MOV [BX],AL
INC BX
MOV AL,0DH
MOV [BX],AL
MOV DX,OFFSET DISP
MOV AH,9
INT 21H
POP SI
POP DX
POP BX
POP AX
RET
PTDN ENDP
QUAN PROC
MOV DL,0
AI: SUB CX,SI
JC DOWN
INC DL
POP AX
OR AL,1
PUSH AX
JMP AI
DOWN: ADD CX,SI
POP AX
PUSH AX
CMP AL,1
JZ ED
CMP DL,0
JZ EN
ED: MOV AL,30H
ADD AL,DL
MOV [BX],AL
INC BX
EN: RET
QUAN ENDP
CODE ENDS
END START