有人能帮帮我吗?以下是任务的详细信息:
您必须构建一个二进制、十进制、八进制、十进制转换器。(最多16位数字)1程序要求用户选择一个基数(H、D、O、B)2程序要求在上述基数中输入一个数字。3如果n
数字不正确,一条错误消息,并返回到程序的开头。4程序将在各个基数中显示这个数字
这是我目前为止所做的。请您帮我检查并满足上述要求,好吗?
我的代码
`DATA SEGMENT
N=16
START_MSG DB "WELCOME TO THE ONLINE BASE CONVERTOR:",'$'
CR DB 10,13,'$'
MSG DB "PLEASE ENTER YOUR BASE TO CONVERT FROM",'$'
CHOOSE DB "FOR HEX='H', DEC='D', OCT='O', BIN='B'.",'$'
MSG_ENTER_NUM DB "PLEASE ENTER YOUR NUMBER:", '$'
NUMBER_H DB N+1, N+2 DUP (?)
NUMBER_D DB N+1, N+2 DUP (?)
NUMBER_B DB N+1, B+2 DUP (?)
NUMBER_O DB N+1, N+2 DUP (?)
LEN DW 0
START_STRING DW 2
NUM_DEC DW 0
USER_CHOOSE DB ?
END_OF_STR DW 0
POWER_LOOP DW 1
LENB DW 0
DATA ENDS
SSEG SEGMENT STACK
DW 100 DUP (?)
SSEG ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:SSEG
START: MOV AX, DATA
MOV DS, AX
MOV DX, OFFSET START_MSG
MOV AH, 9
INT 21H
MOV DX, OFFSET CR
MOV AH, 9
INT 21H
MOV DX, OFFSET MSG
MOV AH, 9
INT 21H
MOV DX, OFFSET CR
MOV AH, 9
INT 21H
MOV DX, OFFSET CHOOSE
MOV AH, 9
INT 21H
MOV DX, OFFSET CR
MOV AH, 9
INT 21H
MOV AH, 1
INT 21H
MOV USER_CHOOSE, AL
MOV DX, OFFSET CR
MOV AH, 9
INT 21H
MOV DX, OFFSET MSG_ENTER_NUM
MOV AH, 9
INT 21H
MOV DX, OFFSET CR
MOV AH, 9
INT 21H
CMP USER_CHOOSE, 72 ; ASCII for H
JE HEX
CMP USER_CHOOSE, 66 ; ASCII for B
JE BINARY
CMP USER_CHOOSE, 68 ; ASCII for D
JE DECIMAL
CMP USER_CHOOSE, 79 ; ASCII for O
JE OCT
HEX:
LEA DX, NUMBER_H
MOV AH, 0AH
INT 21H
MOV SI, 2
COUNT_LEN:
CMP NUMBER_H[SI], 0DH
JE CONTT
INC LEN
INC SI
JMP COUNT_LEN
CONTT:
MOV CX, LEN
MOV SI, START_STRING
MOV END_OF_STR, CX
INC END_OF_STR
MOV DI, END_OF_STR
FROM_CHAR_TO_HEX_NUM:
CMP NUMBER_H[SI], 41H
JNB CONVERT_LATTERS
AND NUMBER_H[SI], 0FH ; Convert ASCII character to hexadecimal digit
CMP NUMBER_H[SI], 9
INC SI
LOOP FROM_CHAR_TO_HEX_NUM
MOV CX, LEN
MOV POWER_LOOP,CX
ADD POWER_LOOP,1
MOV SI, START_STRING
;; MOV SI, LEN
JMP CHANGE_TO_DEC
CONVERT_LATTERS:
AND NUMBER_H[SI], 0FH
ADD NUMBER_H[SI], 9 ; ADJUST FOR LETTERS A-F
JMP FROM_CHAR_TO_HEX_NUM
CHANGE_TO_DEC:
XOR AX, AX
MOV AL, NUMBER_H[SI]
MOV BL, 16
DEC POWER_LOOP
MOV CX, POWER_LOOP ; Initialize CX with LEN
CMP SI, DI
JE ADD_TO_DEC1
;MOV CX, SI
DEC CX
MOV BX, 16
MOV AX, 1
POWER:
MUL BX
LOOP POWER
JMP ADD_TO_DEC
ADD_TO_DEC:
MOV BL, NUMBER_H[SI]
MUL BX
ADD NUM_DEC, AX
CMP NUMBER_H[SI], 0DH
JE BINARY
INC SI
JMP CHANGE_TO_DEC
ADD_TO_DEC1:
MOV AL, NUMBER_H[DI]
MOV BL, 1
MUL BL
ADD NUM_DEC, AX
DEC DI
INC SI
JMP CHANGE_BIN
CHANGE_BIN:
MOV SI, START_STRING
XOR AX, AX
XOR BX, BX
MOV AX, NUM_DEC
MOV BL, 2
DIVIDE:
DIV BX
MOV NUMBER_B[SI], DL
ADD NUMBER_B[SI],30H
INC SI
CMP AL, 1
JNE DIVIDE
BINARY:
MOV NUMBER_B[SI], 31H
MOV SI,2
COUNT_LEN1:
CMP NUMBER_B[SI], 0
JE CONTT1
INC LENB
INC SI
JMP COUNT_LEN1
CONTT1:
LEA DX, NUMBER_B
MOV AH, 0AH
INT 21H
JMP CONTINUE
DECIMAL:
LEA DX, NUMBER_D
MOV AH, 0AH
INT 21H
JMP CONTINUE
OCT:
LEA DX, NUMBER_O
MOV AH, 0AH
INT 21;kH
JMP CONTINUE
CONTINUE:
EXIT:
MOV AH, 4CH
INT 21H
CODE ENDS
END START
`
字符串
我尝试这个和DIVIDE不工作,以及与一个四位数,我失去了我的方式不知道如何继续
1条答案
按热度按时间zqdjd7g91#
我尝试这个和DIVIDE不工作,以及与一个四位数,我失去了我的方式不知道如何继续
除法前未将DX设置为0。在
DIV BX
之前使用XOR DX,DX
。DX必须包含32位被除数的正确高16位。