| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 687 人关注过本帖
标题:看个程序
只看楼主 加入收藏
evasnow
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-12-29
收藏
 问题点数:0 回复次数:3 
看个程序

有高手在吗,帮忙看个程序,结果总是出错

从键盘接收六个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





2005-12-29 14:17
evasnow
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-12-29
收藏
得分:0 

上面是主程序,下面是进制转换
data segment
BUF DB 8
DB 8
DB 8 DUP(?)
VALUE DW 21H
NOTE1 DB 'ENTER THE NUMBER$'
data ends
stack segment stack
db 200h dup(?)
tos label word
stack ends
code segment
assume cs:code,ds:data,ss:stack
main proc far
mov ax,stack
mov ss,ax
mov sp,offset tos
push ds
xor ax,ax
push ax
mov ax,data
mov ds,ax
mov cx,2
MOV DX,OFFSET NOTE1
MOV AH,09H
INT 21H
MOV DL,0AH
MOV AH,2
INT 21H
MOV DL,0DH
MOV AH,2
INT 21H
MOV SI,OFFSET BUF+1
MOV Dx, OFFSET BUF
MOV AH,10
INT 21H
XOR AX,AX
INC SI
MOV AX,[SI]
mov bx,10
lp1: xor dx,dx
div bx
ADD DL,30H
push dx
loop lp1
mov cx,2
MOV DL,0AH
MOV AH,2
INT 21H
MOV DL,0DH
MOV AH,2
INT 21H
lp2: pop dx

mov ah,2
int 21h
loop lp2
ret
main endp
code ends
end main

2005-12-29 14:59
shensheng4
Rank: 1
等 级:新手上路
帖 子:80
专家分:0
注 册:2005-8-7
收藏
得分:0 
我认为有两个错误
1.输入时,题中要求输入16进制数,而你的程序是按照十进制数处理的
2.在消前导0时,使用堆栈可能出现了错误
以下是我的改过的程序,改动的地方用星花注释

梦想是不可能实现的,正因为如此才值得我们去追寻。 这是我选择的路,即使付出一切,我也毫无怨言。
2006-01-05 08:59
shensheng4
Rank: 1
等 级:新手上路
帖 子:80
专家分:0
注 册:2005-8-7
收藏
得分:0 

;从键盘接收六个16进制数(0H~7FFFH)按降序排序输出,输出时为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
;***************************1
MOV AL,[SI]
CMP AL,3AH
JB NEXT11
SUB AL,7H
NEXT11: SUB AL,30H
;***************************1
MOV [DI],AL
INC DI
DEC BL
JNZ NEXT2
POP BX
POP DI
MOV CX,0
AG1: PUSH BX
;***************************2
SHL CX,1
SHL CX,1
SHL CX,1
SHL CX,1
MOV BL,[DI]
MOV BH,0
INC DI
ADD CX,BX
POP BX
;***************************2
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
;***************************3
MOV AL,1
JMP AI
DOWN: ADD CX,SI
CMP AL,0
JNZ ED
CMP DL,0
JZ EN
ED: ADD DL,30H
MOV [BX],DL
;****************************3
INC BX
EN: RET
QUAN ENDP
CODE ENDS
END START





梦想是不可能实现的,正因为如此才值得我们去追寻。 这是我选择的路,即使付出一切,我也毫无怨言。
2006-01-05 09:02
快速回复:看个程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020814 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved