data segment
str0 db 'please input binary less than 16!',0dh,0ah,24h
str1 db 'Binary output',0dh,0ah,24h
str2 db 'Hexadecimal output',0dh,0ah,24h
str3 db 'Octal output',0dh,0ah,24h
str4 db 'Decimal unsigned number output',0dh,0ah,24h
str5 db 'The decimal symbol number output',0dh,0ah,24h
str6 db 'Thanks for your using!',0dh,0ah,24h
str7 db 0dh,0ah,24h
data ends
stacker segment stack
dw 20 dup(?)
top label word
stacker ends
code segment
assume cs:code,ds:data,ss:stacker
start proc near
mov ax,stacker
mov ss,ax
lea sp,top
mov ax,data
mov ds,ax
lea dx,str0
mov ah,09h
int 21h
xor bx,bx
mov cx,16
L1: mov ah,01h
int 21h
cmp al,0dh
je L2
mov dl,30h
cmp al,dl
jb L1
mov dl,31h
cmp al,dl
ja L1
shr al,1
rcl bx,1
loop L1
L2: lea dx,str7
mov ah,09h
int 21h
lea dx,str1
mov ah,09h
int 21h
mov cx,16
L3: rol bx,1
mov dl,30h
adc dl,0
mov ah,02h
int 21h
loop L3
lea dx,str7
mov ah,09h
int 21h
lea dx,str2
mov ah,09h
int 21h
mov cx,4
L4: push cx
mov cl,4
rol bx,cl
mov al,bl
and al,15
cmp al,9
jbe L5
add al,7
L5: add al,30h
mov dl,al
mov ah,02h
int 21h
pop cx
loop L4
lea dx,str7
mov ah,09h
int 21h
lea dx,str3
mov ah,09h
int 21h
rol bx,1
mov al,30h
adc al,0
mov dl,al
mov ah,02h
int 21h
mov cx,5
L6: push cx
mov cl,3
rol bx,cl
mov al,bl
and al,7
add al,30h
mov dl,al
mov ah,02h
int 21h
pop cx
loop L6
lea dx,str7
mov ah,09h
int 21h
lea dx,str4
mov ah,09h
int 21h
mov ax,bx
mov si,10
mov cx,0
L7: xor dx,dx
div si
push dx
inc cx
cmp ax,0
ja L7
L8: pop dx
add dl,30h
mov ah,02h
int 21h
loop L8
lea dx,str7
mov ah,09h
int 21h
lea dx,str5
mov ah,09h
int 21h
or bx,bx
jns L9
mov dl,2dh
mov ah,02h
int 21h
neg bx
L9: mov ax,bx
mov si,10
mov cx,0
L10:xor dx,dx
div si
push dx
inc cx
cmp ax,0
ja L10
L11:pop dx
add dl,30h
mov ah,02h
int 21h
loop L11
lea dx,str7
mov ah,09h
int 21h
lea dx,str6
mov ah,09h
int 21h
mov ah,4ch
int 21h
start endp
code ends
end start
str0 db 'please input binary less than 16!',0dh,0ah,24h
str1 db 'Binary output',0dh,0ah,24h
str2 db 'Hexadecimal output',0dh,0ah,24h
str3 db 'Octal output',0dh,0ah,24h
str4 db 'Decimal unsigned number output',0dh,0ah,24h
str5 db 'The decimal symbol number output',0dh,0ah,24h
str6 db 'Thanks for your using!',0dh,0ah,24h
str7 db 0dh,0ah,24h
data ends
stacker segment stack
dw 20 dup(?)
top label word
stacker ends
code segment
assume cs:code,ds:data,ss:stacker
start proc near
mov ax,stacker
mov ss,ax
lea sp,top
mov ax,data
mov ds,ax
lea dx,str0
mov ah,09h
int 21h
xor bx,bx
mov cx,16
L1: mov ah,01h
int 21h
cmp al,0dh
je L2
mov dl,30h
cmp al,dl
jb L1
mov dl,31h
cmp al,dl
ja L1
shr al,1
rcl bx,1
loop L1
L2: lea dx,str7
mov ah,09h
int 21h
lea dx,str1
mov ah,09h
int 21h
mov cx,16
L3: rol bx,1
mov dl,30h
adc dl,0
mov ah,02h
int 21h
loop L3
lea dx,str7
mov ah,09h
int 21h
lea dx,str2
mov ah,09h
int 21h
mov cx,4
L4: push cx
mov cl,4
rol bx,cl
mov al,bl
and al,15
cmp al,9
jbe L5
add al,7
L5: add al,30h
mov dl,al
mov ah,02h
int 21h
pop cx
loop L4
lea dx,str7
mov ah,09h
int 21h
lea dx,str3
mov ah,09h
int 21h
rol bx,1
mov al,30h
adc al,0
mov dl,al
mov ah,02h
int 21h
mov cx,5
L6: push cx
mov cl,3
rol bx,cl
mov al,bl
and al,7
add al,30h
mov dl,al
mov ah,02h
int 21h
pop cx
loop L6
lea dx,str7
mov ah,09h
int 21h
lea dx,str4
mov ah,09h
int 21h
mov ax,bx
mov si,10
mov cx,0
L7: xor dx,dx
div si
push dx
inc cx
cmp ax,0
ja L7
L8: pop dx
add dl,30h
mov ah,02h
int 21h
loop L8
lea dx,str7
mov ah,09h
int 21h
lea dx,str5
mov ah,09h
int 21h
or bx,bx
jns L9
mov dl,2dh
mov ah,02h
int 21h
neg bx
L9: mov ax,bx
mov si,10
mov cx,0
L10:xor dx,dx
div si
push dx
inc cx
cmp ax,0
ja L10
L11:pop dx
add dl,30h
mov ah,02h
int 21h
loop L11
lea dx,str7
mov ah,09h
int 21h
lea dx,str6
mov ah,09h
int 21h
mov ah,4ch
int 21h
start endp
code ends
end start