store segment stack
db 256 dup(?)
store ends

data segment
char1 db "Enter number, then press enter$"
char2 db "Binary here:$"
char3 db "Press * to exit, or any key to continue$"
data ends

code segment
assume cs:code,ds:data, ss:store
start:
mov ax, data
mov ds,ax

f:mov dx, offset char1

mov ah, 9
int 21h
mov ah,2
mov dl,10
int 21h

mov dx,0
mov cl,10
mov bl,0
mov ax,0
b: mov ah,1
int 21h
cmp al,13
je a
and al,00001111b
push ax
mov al,bl
mul cl
mov bl,al
pop ax
add bl,al
jmp b
a:

mov ah,2
mov dl,10
int 21h
mov dx, offset char2
mov ah, 9
int 21h
mov ah,2
mov dl,10
int 21h
mov dx,0

mov ah,2
mov al,10000000b
mov cx, 8
c: mov dl,bl
and dl, al
cmp dl,0
je d
mov dl,1
d:or dl,30h
push ax
int 21h
pop ax
rcr al,1
loop c


mov ah,2
mov dl,10
int 21h
mov dx,0
mov dx, offset char3
mov ah, 9
int 21h

mov ah,1
int 21h
cmp al,'*'
je e

mov ah,2
mov dl,10
int 21h

jmp f
e:mov ah,4ch
int 21h
code ends
end start