为什么在这里除法会溢出?
;========================数据段============================DATA SEGMENT
BUFF1 DB 10,?,10 DUP(?)
BUFF2 DB 10,?,10 DUP(?)
NUM1 DW ?
NUM2 DW ?
NUMRYI DW 10
NUMRY DW 8
SIGN DB 0
YU DB 0
NOSIG DB 0
MESCNS DB 'Please choose the number system: 1:2 2:8 3:10 4:16',0DH,0AH,'$'
MESNSER DB 'Error1: Wrong Number System!',0DH,0AH,'$'
MESINPN DB 'Please input a number of decimal system: ',0DH,0AH,'$'
MESCHOP DB 'Please choose the operation: + / - / * / /',0DH,0AH,'$'
MESOPER DB 'Error2: Wrong operration!',0DH,0AH,'$'
MESNMER DB 'Error3: Wrong number!',0DH,0AH,'$'
NUM DB 28 DUP(0DH),0DH,0AH,'$'
SRSLT DB 10 DUP(?)
DATA ENDS
;========================数据段============================
;========================堆栈段============================
STACK SEGMENT STACK
DB 128 DUP(?)
STACK ENDS
;========================堆栈段============================
;========================代码段============================
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK
START: MOV AX,DATA
MOV DS,AX
MOV AX,STACK
MOV SS,AX
CALL CHNMY
MOV DX,OFFSET MESINPN
MOV AH,09H
INT 21H
MOV DX,OFFSET BUFF1
CALL INPUT
MOV SI,OFFSET BUFF1+2
CALL TEST1
CALL ZOF
MOV NUM1,AX
MOV DX,OFFSET MESINPN
MOV AH,09H
INT 21H
MOV DX,OFFSET BUFF2
CALL INPUT
MOV SI,OFFSET BUFF2+2
CALL TEST1
CALL ZOF
MOV NUM2,AX
CALL CHOP
;********************************************************
EXIT: MOV AH,01H
INT 21H
MOV AH,4CH
INT 21H
;******************接收字符*****************************
INPUT PROC
MOV AH,0AH
INT 21H
RET
INPUT ENDP
;*******************接收字符*************************
;*******************测试数字合法性*****************************
TEST1 PROC
PUSH SI
MOV BL,[SI]
CMP BL,'-'
JZ FUSHU
JIXUZ: MOV SIGN,0
MOV BL,[SI]
CMP BL,30H
JB NUMERR
CMP BL,39H
JA NUMERR
INC SI
CMP BYTE PTR [SI],0DH
JNZ JIXUZ
POP SI
CALL STN
RET
FUSHU: INC NOSIG
MOV SIGN,1
INC SI
FUSHUZ:MOV BL,[SI]
CMP BL,30H
JB NUMERR
CMP BL,39H
JA NUMERR
INC SI
CMP BYTE PTR [SI],0DH
JNZ FUSHUZ
POP SI
INC SI
CALL STN
RET
NUMERR:
MOV DX,OFFSET MESNMER
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
RET
TEST1 ENDP
;*******************测试数字合法性*****************************
;*******************对负数求反*****************************
ZOF PROC
PUSH AX
CALL SHOWN
POP AX
CMP SIGN,0
JNZ WEIFU
RET
WEIFU: NEG AX
RET
ZOF ENDP
;*******************对负数求反*****************************
;************************数字字符转化为数字****************
STN PROC
XOR AX,AX
XOR BH,BH
NEXT: MUL WORD PTR NUMRYI
MOV BL,[SI]
SUB BL,30H
ADD AX,BX
INC SI
CMP BYTE PTR [SI],0DH
JNZ NEXT
RET
STN ENDP
;************************数字字符转化为数字****************
;***********************加法运算********************
JIA PROC
RET
JIA ENDP
;**********************加法运算 *********************
;**********************减法运算 *********************
JIAN PROC
JIAN ENDP
;**********************减法运算 *********************
;**********************乘法运算 *********************
CHENG PROC
RET
CHENG ENDP
;**********************乘法运算 *********************
;**********************除法运算 *********************
CHU PROC ;***********************************
MOV AX,NUM1
MOV BX,NUM2 ;***********************************
IDIV BX ;***********************************
CMP NOSIG,1
JZ FUDED
MOV SIGN,0 ;******************************
JMP JIEGUOD ;******************************
FUDED: NOT DX
NOT AX
ADD AX,1
ADC DX,0
MOV SIGN,1
JIEGUOD:
CALL SHOWN
MOV SIGN,0
RET ;***********************************
CHU ENDP
;**********************除法运算 *********************
;**********************选择数制 *********************
CHNMY PROC
MOV DX,OFFSET MESCNS
MOV AH,09H
INT 21H
INPNS: MOV AH,01H
INT 21H
CMP AL,31H
JZ NS1
CMP AL,32H
JZ NS2
CMP AL,33H
JZ NS3
CMP AL,34H
JZ NS4
ERRNS: MOV DX,OFFSET MESNSER
MOV AH,09H
INT 21H
JMP INPNS
NS1: MOV NUMRY,2
RET
NS2: MOV NUMRY,8
RET
NS3: MOV NUMRY,10
RET
NS4: MOV NUMRY,16
RET
CHNMY ENDP
;**********************选择数制 *********************
;**********************选择运算 *********************
CHOP PROC
MOV DX,OFFSET MESCHOP
MOV AH,09H
INT 21H
INPOP: MOV AH,01H
INT 21H
CMP AL,'+'
JZ OP1
CMP AL,'-'
JZ OP2
CMP AL,'*'
JZ OP3
CMP AL,'/'
JZ OP4
ERROP: MOV DX,OFFSET MESOPER
MOV AH,09H
INT 21H
JMP INPOP
OP1: CALL JIA
RET
OP2: CALL JIAN
RET
OP3: CALL CHENG
RET
OP4: CALL CHU
RET
;**********************选择运算 *********************
;**********************输出存在DX,AX中的数字*********************
SHOWN PROC
PUSH DX ;保护DX中的数据
MOV SI,27
XOR BX,BX
MOV CX,1
CMP DX,0
JA AG
CMP AX,NUMRY
JAE AG
MOV YU,AL
ADD BYTE PTR YU,30H
PUSH BX
MOV BL,YU
MOV [NUM+SI],BL
POP BX
DEC SI
CMP SIGN,0
JZ ZHENG
MOV [NUM+SI],'-'
JMP CLRS
AG: SUB AX,NUMRY ;数制,可以为2,8,10
SBB DX,0
CMP DX,0
JA KECHU
CMP AX,NUMRY
JAE KECHU
MOV YU,AL
ADD BYTE PTR YU,30H
PUSH BX
MOV BL,YU
MOV [NUM+SI],BL
POP BX
DEC SI
MOV AX,CX
MOV DX,BX
MOV CX,1
XOR BX,BX
CMP DX,0
JA AG
CMP AX,NUMRY
JAE AG
MOV YU,AL
ADD BYTE PTR YU,30H
PUSH BX
MOV BL,YU
MOV [NUM+SI],BL
POP BX
DEC SI
CMP SIGN,0
JZ ZHENG
MOV [NUM+SI],'-'
JMP CLRS
ZHENG: MOV [NUM+SI],0DH
CLRS: DEC SI ;清除字符串中原来的数据
MOV [NUM+SI],0DH
CMP SI,0
JNZ CLRS
SHUCHU:MOV AH,09H
MOV DX,OFFSET NUM
INT 21H
POP DX
RET
KECHU:
ADD CX,1
ADC BX,0
JMP AG
SHOWN ENDP
;**********************输出存在AX中的数字*********************
CODE ENDS
END START
;========================代码段============================
[[it] 本帖最后由 warmsnake323 于 2008-6-15 12:47 编辑 [/it]]