**
更多习题答案见
https://github.com/Lemonreds/assembly-solution
**
试编写一段程序,从键盘接收一个 0-65535 间的十进制无符号数,并在终端上显示与 它等值的二进制数。
2017年6月2日15:57:50
data segment
meg db 0dh,0ah,' bad number !','$'
data ends
stack segment stack
dw 20h dup(?)
top label word
stack ends
code segment
assume cs:code,ds:data,ss:stack
main proc far
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
lea sp,top
mov cx,5 ;max number is 65535
xor bx,bx
l1: mov ah,01h
int 21h
cmp al,0dh
je input
and ax,1111b;输入的是ASC码值 转换为 数值
xchg ax,bx
mov si,10
mul si
jc eror
add bx,ax
jc eror
loop l1
input:
mov dl,0ah
mov ah,02h
int 21h
mov cx,16
l2: rol bx,1
mov dl,bl
and dl,1
add dl,30h
mov ah,02h
int 21h
loop l2
jmp exit
eror:
lea dx,meg
mov ah,09h
int 21h
exit:
mov ah,4ch
int 21h
main endp
code ends
end main