汇编语言编程:键入两个8进制数字,相加后以16进制输出
;==============================================
推荐答案 2011-12-24 10:20
程序如下:
;----------------------------------------------
TITLE 从键盘输入两位8进制数,相加后输出其16进制数形式
;----------------------------------------------
DISP_STR MACRO X ;宏定义.
MOV DX, OFFSET X
MOV AH, 9
INT 21H
ENDM
;----------------------------------------------
DATA SEGMENT ;数据段.
MSG1 DB 13, 10, 'Please Input (0~7): $'
MSG3 DB 13, 10, 'The SUM is : $'
x DB ? ;存放输入数据.
DATA ENDS
;----------------------------------------------
CODE SEGMENT ;代码段.
ASSUME CS: CODE, DS: DATA
START:
MOV AX, DATA
MOV DS, AX
;--------------------------------
DISP_STR MSG1 ;宏调用,提示 Please Input :
;--------------------------------
_INX:
MOV AH, 1 ;输入字符.
INT 21H
CMP AL, '0'
JB _IN_END ;小于'0',不是数字.
CMP AL, 37H
JA _IN_END ;大于'7',不是数字.
SUB AL, '0'
MOV x, AL
;--------------------------------
DISP_STR MSG1 ;宏调用,提示 Please Input :
;--------------------------------
_INY:
MOV AH, 1 ;输入字符.
INT 21H
CMP AL, '0'
JB _IN_END ;小于'0',不是数字.
CMP AL, 37H
JA _IN_END ;大于'7',不是数字.
SUB AL, '0'
ADD AL, x
MOV x, AL
;--------------------------------
_IN_END:
DISP_STR MSG3 ;宏调用,提示 The SUM is :
MOV DL, x
CMP DL, 10
JB A30
ADD DL, 7
A30:
ADD DL, '0'
MOV AH, 2 ;显示DL中的ASCII码.
INT 21H
;--------------------------------
MOV AH, 4CH
INT 21H
;--------------------------------
CODE ENDS
END START
;==============================================
程序执行后,屏幕显示如下:
C:\MASM>88_16
Please Input (0~7): 2
Please Input (0~7): 6
The SUM is : 8
C:\MASM>88_16
Please Input (0~7): 7
Please Input (0~7): 6
The SUM is : D
C:\MASM>88_16
Please Input (0~7): 8
The SUM is : 0
C:\MASM>
;==============================================
题目网址:http://zhidao.baidu.com/question/357939958.html
;==============================================