;输入64就会显示0000 0000 1000 0000B,屏幕会提示输入信息:please input decimal number:
;程序源代码如下:
data segment
buf db 0ah,0dh,'please input decimal number:$'
b_x db 10
data ends
stack segment
db 128 dup(0)
stack ends
code segment
assume cs:code,ds:data,ss:stack
start:mov ax,data
mov ds,ax
lea dx,buf ;输出字符串buf,提示输入
mov ah,9
int 21h
mov bx,0
mov ax,0
input:mov ah,1 ;输入一个字符
int 21h
cmp al,0dh ;若为回车键,则跳转到binary
jz binary
cmp al,1bh ;若为退出键、27、1b、Esc,则跳转至exit(退出)
je exit
and al,0fh ;高四位置0,等价于 sub al,30h
;-------- (bx)=(bx)*10+(ax)
cbw
xchg ax,bx ;交换AX,BX
mul b_x
add bx,ax
jmp input
binary: mov ah,2
mov dl,0ah ;输出换行
int 21h
mov cx,16 ;输出16位二进制数
disp: mov dl,0
rol bx,1 ;循环左移一位,最高位到最右
rcl dl,1 ;带进位循环左移一位
or dl,30h ;or 00000000,00110000b dl='0' ???????????????
mov ah,02h ;输出一位
int 21h
loop disp
mov dl,'B' ;输出'B'
mov ah,2
int 21h
exit: mov ah,4ch
int 21h
code ends
end start