ryukifaiz 0 Newbie Poster

I am writing an x86 assembly language program that between base numbers.My problem is how to make it happen like this:

Welcome
1. Binary <-> Octal
2. Binary <-> Decimal
3. Binary <-> Hexadecimal
4. Octal <-> Decimal
5. Octal <-> Hexadecimal
6. Decimal <-> Hexadecimal
Please enter the type of conversion: 2

Available options:
1. Binary -> Decimal
2. Decimal -> Binary
Please enter your option: 1

Hope someone can guide me

data segment 
mesg1 db ‘Welcome to base conversion!’ ',13,10
            db '1. Binary <-> Octal',13,10 
            db '2. Binary <-> Decimal',13,10 
            db '3. Binary <-> Hexadecimal',13,10 
            db '4. Octal <-> Decimal',13,10 
            db '5. Octal <-> Hexadecimal',13,10 
        db '6. Decimal <-> Hexadecimal',13,10 
            db'Please enter the type of conversion: ',13,10
mesg2 db `Available options:’,13,10
             db`1. Binary -> Octal’,13,10
         db`2. Octal -> Binary’,13,10
         db`Please enter your option: ‘,13,10
mesg3 db `Available options:’,13,10
        db`1. Binary -> Decimal’,13,10
        db`2.Decimal -> Binary’,13,10
        db`Please enter your option: ‘,13,10
mesg4 db `Available options:’,13,10
        db`1.Binary -> Hexadecimal’,13,10
        db`2.Hexadecimal -> Binary’,13,10
        db`Please enter your option: ‘,13,10
mesg5 db` Available options:’,13,10
        db`1.Octal -> Decimal’,13,10
       db`2.Decimal -> Octal’,13,10
       db`Please enter your option: ‘,13,10
mesg6 db` Available options:’,13,10
       db`1.Octal ->Hexadecimal’,13,10
       db2.Hexadecimal ->Octal’,13,10
       db`Please enter your option: ‘,13,10
mesg7 db` Available options:’,13,10
        db`1.Decimal ->Hexadecimal’,13,10
        db`2.Hexadecimal ->Decimal’,13,10
        db`Please enter your option: ‘,13,10
mesg8 db`Please enter the binary number: ‘,13,10
mesg9 db`Please enter the octal number: ‘,13,10
mesg10 db`Please enter the decimal number: ‘,13,10
mesg11 db`Please enter the hexadecimal number: ‘,13,10
mesg12 db`Equivalent decimal number:’,13,10
mesg13 db`Equivalent binary number:’,13,10
mesg14 db`Equivalent octal number:’,13,10
mesg15 db`Equivalent hexadecimal number:’,13,10
data ends
code segment 
main proc far
assume cs:code,ds:data 
start:
push ds 
xor ax,ax 
push ax 
mov ax,data 
mov ds,ax 
again: 
   lea dx,mesg1 
   mov ah,16h 
   int 21h 
repeat: 
mov ah,1 
int 21h 
cmp al,31h 
je L1 
cmp al,32h 
je L2 
cmp al,33h 
je L3 
cmp al,34h 
je L4 
cmp al,35h 
je L5 
cmp al,36h 
je L6 
jmp repeat
again:
  lea dx,mesg2 
  mov ah,16
  int 21h 
repeat: 
  mov ah,2 
  int 21h
  cmp al,37h 
  je L7 
  je L8 
jmp repeat
again:
  lea dx,mesg3 
  mov ah,16 
  int 21h 
repeat: 
  mov ah,2 
  int 21h
 cmp al,38h
  je L9
  je L10
jmp repeat
again:
  lea dx,mesg4 
  mov ah,16
  int 21h 
repeat: 
  mov ah,2 
  int 21h
cmp al,39h
je L11
je L12
jmp repeat
again:
  lea dx,mesg5 
  mov ah,16 
  int 21h 
repeat: 
  mov ah,2 
  int 21h

cmp al,40h
je L13
je L14
jmp repeat
again:
  lea dx,mesg6 
  mov ah,16 
  int 21h 
repeat: 
  mov ah,2 
  int 21h
cmp al,41h
je L15
je L16
jmp repeat 
L1: 
call binoct_octbin
call crlf 
jmp again 
L2: 
call bindec_decbin
call crlf 
jmp again 
L3: 
call binhex_hexbin
call crlf 
jmp again 
L4: 
call octdec_octdec
call crlf 
jmp again 
L5: 
call octhex_hexoct
call crlf 
jmp again 
L6: 
call dechex_hexdec
call crlf 
jmp again 
L7: 
call binoct
call crlf 
jmp again 
L8: 
call octbin 
call crlf 
jmp again 
L9: 
call bindec
call crlf 
jmp again 
L10: 
call decbin 
call crlf 
jmp again 
L11: 
call binhex
call crlf 
jmp again 
L12: 
call hexbin
call crlf 
jmp again 
L13:
call octdec
call crlf
jmp again
L14:
call decoct
call crlf
jmp again
L15:
call octhex
call crlf
jmp again
L16:
call hexoct
call crlf
jmp again
ret 
main endp
binhex proc near                                  ;binary to hexadecimal
xor ax,ax 
mov bx,ax 
lea dx,mesg8
mov ah,9 
int 21h 
mov si,4 
newchar1: 
mov ah,1 
int 21h 
sub al,30h 
jl rotate1 
cmp al,10d 
jl add_to1 
jmp rotate1 
add_to1:                   ;save bin to bx 
   mov cl,1 
   shl bx,cl 
   mov ah,0 
   add bx,ax 
   jmp newchar1 
rotate1: 
lea dx,mesg15
mov ah,9 
int 21h 
rotate1_1: 
mov cl,4 
rol bx,cl 
mov al,bl 
and al,0fh 
add al,30h 
cmp al,3ah 
jl print1 
add al,7h 
print1: 
mov dl,al 
mov ah,2 
int 21h 
dec si 
jnz rotate1_1 
ret 
binhex endp
hexbin proc near                              ;hexadecimal to binary
mov bx,0 
lea dx,mesg11
mov ah,9 
int 21h 
mov si,16 
newchar2: 
mov ah,1 
int 21h 
sub al,30h 
jl print2 
cmp al,10d 
jl add_to2 
sub al,27h 
cmp al,0ah 
jl print2 
cmp al,10h 
jge print2 
add_to2: 
mov cl,4 
shl bx,cl 
mov ah,0 
add bx,ax 
jmp newchar2 

lea dx,mesg13 
mov ah,9 
int 21h 
print2: 
rol bx,1 
mov al,bl 
and al,1h 
add al,30h 
mov dl,al 
mov ah,2 
int 21h 
dec si 
jnz print2 
ret 
hexbin endp
decbin proc near                              ;decimal to binary
lea dx,mesg10 
mov ah,9 
int 21h 
mov bx,0 
newchar3: 
mov ah,1 
int 21h 
sub al,30h 
jl print3 
cmp al,9d 
jg print3 
cbw 
xchg ax,bx 
mov cx ,10d 
mul cx 
xchg ax,bx 
add bx,ax 
jmp newchar3 
print3: 
lea dx,mesg13 
mov ah,9 
int 21h 
rol bx,1 
mov al,bl 
and al,1h 
add al,30h 
mov dl,al 
mov ah,2 
int 21h 
dec si 
jnz print3 
ret 
decbin endp
bindec proc near                                ;binary to decimal
lea dx,mesg8
mov ah,9 
int 21h 
newchar4: 
mov ah,1 
int 21h 
sub al,30h 
jl print4 
cmp al,10d 
jl add_to4 
jmp print4 
add_to4: 
   mov cl,1 
   shl bx,cl 
   mov ah,0 
   add bx,ax 
   jmp newchar4 
print4: 
lea dx,mesg12 
mov ah,9 
int 21h                ;display dec 
mov cx,10000d 
call dec_div4 
mov cx,1000 
call dec_div4 
mov cx,100 
call dec_div4 
mov cx,10 
call dec_div4 
mov cx,1 
call dec_div4 
ret 
dec_div4 proc near 
mov ax,bx 
mov dx,0 
div cx 
mov bx,dx 
mov dl,al 
add dl,30h 
mov ah,2 
int 21h 
ret 
dec_div4 endp 
bindec endp
hexdec proc near                                 ;hexadecimal to decimal
lea dx,mesg11 
mov ah,9 
int 21h 
mov bx,0 
newchar5: 
mov ah,1 
int 21h 
sub al,30h 
jl next5 
cmp al,10d 
jl add_to5 
sub al,27h 
cmp al,0ah 
jl next5 
cmp al,10h 
jge next5 
add_to5: 
mov cl,4 
shl bx,cl 
mov ah,0 
add bx,ax 
jmp newchar5 
next5: 
lea dx,mesg12
mov ah,9 
int 21h                ;display dec 
mov cx,10000d 
call dec_div5 
mov cx,1000d 
call dec_div5 
mov cx,100d 
call dec_div5 
mov cx,10d 
call dec_div5 
mov cx,1d 
call dec_div5 
ret 
hexdec endp 
dec_div5 proc near 
mov ax,bx 
mov dx,0 
div cx 
mov bx,dx 
mov dl,al 
add dl,30h 
mov ah,2 
int 21h 
ret 
dec_div5 endp
dechex proc near                     ;decimal to hexadecimal
lea dx,mesg10 
mov ah,9 
int 21h 
mov bx,0 
newchar6: 
mov ah,1 
int 21h 
sub al,30h 
jl next6 
cmp al,9d 
jg next6 
cbw 
xchg ax,bx 
mov cx,10d 
mul cx 
xchg ax,bx 
add bx,ax 
jmp newchar6 
next6: 
mov si,4 
lea dx,mesg15
mov ah,9 
int 21h 
rotate6: 
mov cl,4 
rol bx,cl 
mov al,bl 
and al,0fh 
add al,30h 
cmp al,3ah 
jl print6 
add al,7h 
print6: 
mov dl,al 
mov ah,2 
int 21h 
dec ch 
jnz rotate6 
ret 
dechex endp
crlf proc near 
mov dl,13 
mov ah,2 
int 21h 
mov dl,10 
mov ah,2 
int 21h 
ret 
crlf endp 
prognam ends 
end start