.model small
.stack
.data
msg1 db "Enter hexadecimal number:$"
msg2 db "The binary value is:$"
msg3 db "The number of 1's is:$"
msg4 db "The number of 0's is:$"
countone db ?
countzero db ?
.code
main proc
mov ax,@data
mov ds,ax
clear:
mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
mov ah,9
lea dx,msg1
int 21h
xor bh,bh
input:
mov ah,1
int 21h
mov ch,al
cmp ch,0dh
je print
cmp ch,'0'
jl exit
cmp ch,'1'
jg exit
and ch,15
shl bh,1
or bh,ch
jmp input
print:
mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
mov ah,9
lea dx,msg2
int 21h
mov ah,2
cmp bh,9
jle number
cmp bh,15
jle character
number:
add bh,48
mov ah,2
mov dl,bh
int 21h
mov ah,2
mov dl,13
int 21h
mov dl,10
int 21h
mov ah,9
lea dx,msg3
int 21h
mov ah,2
mov dl,13
int 21h
mov dl,10
int 21h
mov ah,9
lea dx,msg4
int 21h
jmp clear
character:
add bh,55
mov ah,2
mov dl,bh
int 21h
mov ah,2
mov dl,13
int 21h
mov dl,10
int 21h
mov ah,9
lea dx,msg3
int 21h
mov ah,2
mov dl,13
int 21h
mov dl,10
int 21h
mov ah,9
lea dx,msg4
int 21h
jmp clear
exit:
mov ah,2
mov dl,0dh
int 21h
mov dl,0ah
int 21h
mov ah,4ch
int 21h
main endp
END main