汇编语言中如何编写输入输出程序(输入十进制数,输出十六进制数)?
答案:1 悬赏:20 手机版
解决时间 2021-03-20 02:04
- 提问者网友:ミ烙印ゝ
- 2021-03-19 14:37
汇编语言中如何编写输入输出程序(输入十进制数,输出十六进制数)?
最佳答案
- 五星知识达人网友:鸠书
- 2021-03-19 15:56
CODE SEGMENT
ASSUME CS:CODE
MAIN PROC FAR
START:
CALL DEC_BIN
CALL BIN_HEX
call dec_bin1
call BINIDEC
MOV AH,4CH
INT 21H
RET
MAIN ENDP
DEC_BIN PROC NEAR
MOV BX,0
GET_CHAR:MOV AH,1
INT 21H
CMP AL,0DH
JE EXIT
SUB AL,30H
JL EXIT
CMP AL,9
JG EXIT
CBW
XCHG AX,BX
MOV CX,10
MUL CX
XCHG AX,BX
ADD BX,AX
JMP GET_CHAR
EXIT:
mov dl,0ah
mov ah,2
int 21h
RET
DEC_BIN ENDP
BIN_HEX PROC NEAR
MOV CH,4
ROTATE:MOV CL,4
ROL BX,CL
MOV AL,BL
AND AL,0FH
ADD AL,30H
CMP AL,3AH
JL DISPLAY
ADD AL,7H
DISPLAY:MOV DL,AL
MOV AH,2
INT 21H
DEC CH
JNZ ROTATE
mov dl,0ah
mov ah,2
int 21h
RET
BIN_HEX ENDP
DEC_BIN1 PROC NEAR
MOV BX,0
GET_CHAR1:MOV AH,1
INT 21H
CMP AL,0DH
JE EXIT1
SUB AL,30H
JL EXIT1
CMP AL,9
Jle t0
SUB AL,7H
CMP AL,15
jg exit1
t0:CBW
XCHG AX,BX
mov cl,4
rol ax,cl
ADD BX,AX
JMP GET_CHAR1
EXIT1:mov dl,0ah
mov ah,2
int 21h
RET
DEC_BIN1 ENDP
BINIDEC PROC NEAR
MOV CX,1000
CALL DEC_DIV
MOV CX,100
CALL DEC_DIV
MOV CX,10
CALL DEC_DIV
MOV CX,1
CALL DEC_DIV
RET
BINIDEC ENDP
DEC_DIV PROC NEAR
MOV AX,BX
MOV DX,0
DIV CX
MOV BX,DX
CMP AL,9
ADD AL,30H
MOV DL,AL
MOV AH,2
INT 21H
RET
DEC_DIV ENDP
CODE ENDS
END START
ASSUME CS:CODE
MAIN PROC FAR
START:
CALL DEC_BIN
CALL BIN_HEX
call dec_bin1
call BINIDEC
MOV AH,4CH
INT 21H
RET
MAIN ENDP
DEC_BIN PROC NEAR
MOV BX,0
GET_CHAR:MOV AH,1
INT 21H
CMP AL,0DH
JE EXIT
SUB AL,30H
JL EXIT
CMP AL,9
JG EXIT
CBW
XCHG AX,BX
MOV CX,10
MUL CX
XCHG AX,BX
ADD BX,AX
JMP GET_CHAR
EXIT:
mov dl,0ah
mov ah,2
int 21h
RET
DEC_BIN ENDP
BIN_HEX PROC NEAR
MOV CH,4
ROTATE:MOV CL,4
ROL BX,CL
MOV AL,BL
AND AL,0FH
ADD AL,30H
CMP AL,3AH
JL DISPLAY
ADD AL,7H
DISPLAY:MOV DL,AL
MOV AH,2
INT 21H
DEC CH
JNZ ROTATE
mov dl,0ah
mov ah,2
int 21h
RET
BIN_HEX ENDP
DEC_BIN1 PROC NEAR
MOV BX,0
GET_CHAR1:MOV AH,1
INT 21H
CMP AL,0DH
JE EXIT1
SUB AL,30H
JL EXIT1
CMP AL,9
Jle t0
SUB AL,7H
CMP AL,15
jg exit1
t0:CBW
XCHG AX,BX
mov cl,4
rol ax,cl
ADD BX,AX
JMP GET_CHAR1
EXIT1:mov dl,0ah
mov ah,2
int 21h
RET
DEC_BIN1 ENDP
BINIDEC PROC NEAR
MOV CX,1000
CALL DEC_DIV
MOV CX,100
CALL DEC_DIV
MOV CX,10
CALL DEC_DIV
MOV CX,1
CALL DEC_DIV
RET
BINIDEC ENDP
DEC_DIV PROC NEAR
MOV AX,BX
MOV DX,0
DIV CX
MOV BX,DX
CMP AL,9
ADD AL,30H
MOV DL,AL
MOV AH,2
INT 21H
RET
DEC_DIV ENDP
CODE ENDS
END START
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯