如何编写一个汇编语言源程序,将键盘输入的ASCII码转换为二进制?
展开全部
;将键盘输入的ASCII码转换为二进制。
;直接回车程序结束。
;.com 文件格式
code segment
main proc far
assume cs:code,ds:code
org 100h
start:
PUSH CS
POP DS
NN1:
MOV AH,02
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H
mov ah,01
int 21h
cmp al,0dh
jnz goon
jmp endd
goon:
push ax
mov ah,09
lea dx,s1
int 21h
pop ax
call disp1
JMP NN1
endd:
INT 20H
S1 DB ' ASCII ========> ',24H
main endp
;--------------------------------
disp1 proc near
MOV BL,AL
mov cx,8
NEXT:
shl BL,1 ;逻辑左移
JC IS_1
MOV DL,30H
JMP XS1
IS_1:
MOV DL,31H
XS1:
MOV AH,02
INT 21H
LOOP NEXT
ret
disp1 endp
;--------------------------------
code ends
end start
以下是运行结果:
7 ASCII ========> 00110111
6 ASCII ========> 00110110
2 ASCII ========> 00110010
3 ASCII ========> 00110011
b ASCII ========> 01100010
s ASCII ========> 01110011
d ASCII ========> 01100100
h ASCII ========> 01101000
j ASCII ========> 01101010
x ASCII ========> 01111000
8 ASCII ========> 00111000
j ASCII ========> 01101010
f ASCII ========> 01100110
e ASCII ========> 01100101
;直接回车程序结束。
;.com 文件格式
code segment
main proc far
assume cs:code,ds:code
org 100h
start:
PUSH CS
POP DS
NN1:
MOV AH,02
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H
mov ah,01
int 21h
cmp al,0dh
jnz goon
jmp endd
goon:
push ax
mov ah,09
lea dx,s1
int 21h
pop ax
call disp1
JMP NN1
endd:
INT 20H
S1 DB ' ASCII ========> ',24H
main endp
;--------------------------------
disp1 proc near
MOV BL,AL
mov cx,8
NEXT:
shl BL,1 ;逻辑左移
JC IS_1
MOV DL,30H
JMP XS1
IS_1:
MOV DL,31H
XS1:
MOV AH,02
INT 21H
LOOP NEXT
ret
disp1 endp
;--------------------------------
code ends
end start
以下是运行结果:
7 ASCII ========> 00110111
6 ASCII ========> 00110110
2 ASCII ========> 00110010
3 ASCII ========> 00110011
b ASCII ========> 01100010
s ASCII ========> 01110011
d ASCII ========> 01100100
h ASCII ========> 01101000
j ASCII ========> 01101010
x ASCII ========> 01111000
8 ASCII ========> 00111000
j ASCII ========> 01101010
f ASCII ========> 01100110
e ASCII ========> 01100101
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询