设计汇编语言程序
发布网友
发布时间:2022-04-30 15:23
我来回答
共1个回答
热心网友
时间:2022-06-26 06:10
;=================================
DATA SEGMENT
MSG0 DB 13, 10, 'This Program Can Change CHAR to BIN and HEX.$'
MSG1 DB 13, 10, 'Please input a char (Enter will finish program) : ', '$'
DATA ENDS
;---------------------------------
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV DX, OFFSET MSG0
MOV AH, 9 ;9号功能调用,显示提示.
INT 21H ;显示.
;---------------------------------
LOP:
MOV DX, OFFSET MSG1
MOV AH, 9 ;9号功能调用,显示提示.
INT 21H ;显示.
MOV AH, 1 ;1号功能调用,键入、显示.
INT 21H ;
CMP AL, 13
JZ EXIT ;回车就结束.
PUSH AX
MOV AH, 2
MOV DL, 32 ;空格.
INT 21H
MOV DL, '-'
INT 21H
MOV DL, '-'
INT 21H
MOV DL, '>'
INT 21H
MOV DL, ' '
INT 21H
;------------------------
POP AX
CALL CHANUM ;调用显示程序.
JMP LOP
;---------------------------------
EXIT:
MOV AH, 4CH
INT 21H
;---------------------------------
CHANUM: ;显示AL中的ASCII码.
PUSH AX
;------------------------
MOV CX, 8 ;显示8位二进制数.
MOV AH, 2
B1:
MOV DL, '0'
CMP AL, 80H
JB B2
INC DL
B2:
PUSH AX
INT 21H
POP AX
ADD AL, AL
LOOP B1
;------------------------
MOV AH, 2
MOV DL, 'B' ;显示B,
INT 21H
MOV DL, ','
INT 21H
MOV DL, ' '
INT 21H
;------------------------
POP AX ;下面显示两位16进制数.
MOV AH, 0
MOV BL, 16
DIV BL
PUSH AX
MOV DL, AL
ADD DL, '0'
CMP DL, 3AH
JB H1
ADD DL, 7
H1:
MOV AH, 2
INT 21H
POP AX
MOV DL, AH
ADD DL, '0'
CMP DL, 3AH
JB H2
ADD DL, 7
H2:
MOV AH, 2
INT 21H
;------------------------
MOV AH, 2
MOV DL, 'H' ;显示H.
INT 21H
MOV DL, '.'
INT 21H
RET
;---------------------------------
CODE ENDS
END START
;=================================