1 Replies - 419 Views - Last Post: 04 January 2014 - 06:48 AM

#1 crazyhawk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-January 14

Need help in base conversion!

Posted 04 January 2014 - 04:18 AM

we are required to do a base conversion. there are 12 conversions. binary to octal, octal to binary, binary to decimal, decimal to binary and so on with hexadecimal. our concept is convert all input to decimal and convert back to the base that the user wanted. here is our code. we stuck at converting all base to decimal.


                              
org 100h
                                      
jmp start

msg:    db "Welcome to base conversion!", 0Dh,0Ah, 24h        
msg1:    db "1.Binary  <-> Octal", 0Dh,0Ah, 24h
msg2:    db "2.Binary  <-> Decimal", 0Dh,0Ah, 24h
msg3:    db "3.Binary  <-> Hexadecimal", 0Dh,0Ah, 24h
msg4:    db "4.Octal   <-> Decimal", 0Dh,0Ah, 24h
msg5:    db "5.Octal   <-> Hexadecimal", 0Dh,0Ah, 24h
msg6:    db "6.Decimal <-> Hexadecimal", 0Dh,0Ah, 24h
msg7:    db "Please enter the type of conversion: $",0Dh,0Ah, 24h
 
msga1:   db " " ,10,13 
msgb1:   db "Available options:", 0Dh,0Ah,
msgc1:   db "1. Binary -> Octal" , 0Dh,0Ah
msgd1:   db "2. Octal -> Binary" , 0Dh,0Ah
msge1:   db "Please enter your option: $" , 0Dh,0Ah
msga2:   db " " ,10,13 
msgb2:   db "Available options:", 0Dh,0Ah
msgc2:   db "1. Binary -> Decimal" , 0Dh,0Ah
msgd2:   db "2. Decimal -> Binary" , 0Dh,0Ah
msge2:   db "Please enter your option: $" , 0Dh,0Ah
msga3:   db " " ,10,13
msgb3:   db "Available options:", 0Dh,0Ah
msgc3:   db "1. Binary -> Hexadecimal" , 0Dh,0Ah
msgd3:   db "2. Hexadecimal -> Binary" , 0Dh,0Ah
msge3:   db "Please enter your option: $" , 0Dh,0Ah
msga4:   db " " ,10,13
msgb4:   db "Available options:", 0Dh,0Ah
msgc4:   db "1. Octal -> Decimal" , 0Dh,0Ah
msgd4:   db "2. Decimal -> Octal" , 0Dh,0Ah
msge4:   db "Please enter your option: $" , 0Dh,0Ah
msga5:   db " " ,10,13
msgb5:   db "Available options:", 0Dh,0Ah
msgc5:   db "1. Octal -> Hexadecimal" , 0Dh,0Ah
msgd5:   db "2. Hexadecimal -> Octal" , 0Dh,0Ah
msge5:   db "Please enter your option: $" , 0Dh,0Ah
msga6:   db " " ,10,13
msgb6:   db "Available options:", 0Dh,0Ah
msgc6:   db "1. Decimal -> Hexadecimal" , 0Dh,0Ah
msgd6:   db "2. Hexadecimal -> Decimal" , 0Dh,0Ah
msge6:   db "Please enter your option: $" , 0Dh,0Ah

msg1a:   db " " ,10,13
msg1b:   db "Please enter the Binary number: $", 0Dh,0Ah
msg2a:   db " " ,10,13
msg2b:   db "Please enter the Octal number: $", 0Dh,0Ah
msg3a:   db " " ,10,13
msg3b:   db "Please enter the Decimal number: $", 0Dh,0Ah
msg4a:   db " " ,10,13
msg4b:   db "Please enter the Hexadecimal number: $", 0Dh,0Ah
        
start:  mov dx, msg
        mov ah, 09h 
        int 21h
        mov dx, msg1
        mov ah, 09h 
        int 21h
        mov dx, msg2
        mov ah, 09h 
        int 21h
        mov dx, msg3
        mov ah, 09h 
        int 21h
        mov dx, msg4
        mov ah, 09h 
        int 21h
        mov dx, msg5
        mov ah, 09h 
        int 21h
        mov dx, msg6
        mov ah, 09h 
        int 21h 
        mov dx, msg7
        mov ah, 09h 
        int 21h
                
start1: mov ah, 1 
        int 21h        
        cmp al, '1'
        jz msgp1
        cmp al, '2'
        jz msgp2
        cmp al, '3'
        jz msgp3
        cmp al, '4'
        jz msgp4
        cmp al, '5'
        jz msgp5
        cmp al, '6'
        jz msgp6
        
print1: mov ah, 9
        int 21h
        jmp start2          
        mov ah, 0 
        int 16h        
print2: mov ah, 9
        int 21h
        jmp start3          
        mov ah, 0 
        int 16h        
print3: mov ah, 9
        int 21h
        jmp start4          
        mov ah, 0 
        int 16h
print4: mov ah, 9
        int 21h
        jmp start5          
        mov ah, 0 
        int 16h
print5: mov ah, 9
        int 21h
        jmp start6          
        mov ah, 0 
        int 16h        
print6: mov ah, 9
        int 21h
        jmp start7          
        mov ah, 0 
        int 16h
             
msgp1:  mov dx, offset msga1
        jmp print1
        mov dx, offset msgb1
        jmp print1
        mov dx, offset msgc1
        jmp print1
        mov dx, offset msgd1
        jmp print1
        mov dx, offset msge1
        jmp print1               
msgp2:  mov dx, offset msga2
        jmp print2
        mov dx, offset msgb2
        jmp print2
        mov dx, offset msgc2
        jmp print2
        mov dx, offset msgd2
        jmp print2
        mov dx, offset msge2
        jmp print2                 
msgp3:  mov dx, offset msga3
        jmp print3
        mov dx, offset msgb3
        jmp print3
        mov dx, offset msgc3
        jmp print3
        mov dx, offset msgd3
        jmp print3
        mov dx, offset msge3
        jmp print3         
msgp4:  mov dx, offset msga4
        jmp print4
        mov dx, offset msgb4
        jmp print4
        mov dx, offset msgc4
        jmp print4
        mov dx, offset msgd4
        jmp print4
        mov dx, offset msge4
        jmp print4         
msgp5:  mov dx, offset msga5
        jmp print5
        mov dx, offset msgb5
        jmp print5
        mov dx, offset msgc5
        jmp print5
        mov dx, offset msgd5
        jmp print5
        mov dx, offset msge5
        jmp print5                                 
msgp6:  mov dx, offset msga6
        jmp print6
        mov dx, offset msgb6
        jmp print6
        mov dx, offset msgc6
        jmp print6
        mov dx, offset msgd6
        jmp print6
        mov dx, offset msge6
        jmp print6                                  

start2: mov ah, 1
        int 21h        
        cmp al, '1'
        jz msgs1
        cmp al, '2'
        jz msgs2
        
printa: mov ah, 9
        int 21h
        jmp new          
        mov ah, 0 
        int 16h
        
msgs1:  mov dx, offset msg1a
        jmp printa
        mov dx, offset msg1b
        jmp printa        
msgs2:  mov dx, offset msg2a
        jmp printa
        mov dx, offset msg2b
        jmp printa 

start3: mov ah, 1
        int 21h        
        cmp al, '1'
        jz msgs3
        cmp al, '2'
        jz msgs4
        
printb: mov ah, 9
        int 21h
        jmp new          
        mov ah, 0 
        int 16h
        
msgs3:  mov dx, offset msg1a
        jmp printb
        mov dx, offset msg1b
        jmp printb        
msgs4:  mov dx, offset msg3a
        jmp printb
        mov dx, offset msg3b
        jmp printb
        
start4: mov ah, 1
        int 21h        
        cmp al, '1'
        jz msgs5
        cmp al, '2'
        jz msgs6        

printc: mov ah, 9
        int 21h
        jmp new          
        mov ah, 0 
        int 16h        

msgs5:  mov dx, offset msg1a
        jmp printc
        mov dx, offset msg1b
        jmp printc        
msgs6:  mov dx, offset msg4a
        jmp printc
        mov dx, offset msg4b
        jmp printc        

start5: mov ah, 1
        int 21h        
        cmp al, '1'
        jz msgs7
        cmp al, '2'
        jz msgs8
        
printd: mov ah, 9
        int 21h
        jmp new          
        mov ah, 0 
        int 16h
        
msgs7:  mov dx, offset msg2a
        jmp printd
        mov dx, offset msg2b
        jmp printd        
msgs8:  mov dx, offset msg3a
        jmp printd
        mov dx, offset msg3b
        jmp printd

start6: mov ah, 1
        int 21h        
        cmp al, '1'
        jz msgs9
        cmp al, '2'
        jz msgs10
        
printe: mov ah, 9
        int 21h
        jmp new          
        mov ah, 0 
        int 16h
        
msgs9:  mov dx, offset msg2a
        jmp printe
        mov dx, offset msg2b
        jmp printe        
msgs10: mov dx, offset msg4a
        jmp printe
        mov dx, offset msg4b
        jmp printe

start7: mov ah, 1
        int 21h        
        cmp al, '1'
        jz msgs11
        cmp al, '2'
        jz msgs12
        
printf: mov ah, 9
        int 21h
        jmp new          
        mov ah, 0 
        int 16h
        
msgs11: mov dx, offset msg3a
        jmp printf
        mov dx, offset msg3b
        jmp printf        
msgs12: mov dx, offset msg4a
        jmp printf
        mov dx, offset msg4b
        jmp printf

new:    mov ah, 10
        int 21h
        lea dx, num                 
        loop new
           
num     db 32 bup ( )         

ret


*** EDIT ***
Please use code tags when posting code
:code:

This post has been edited by GunnerInc: 04 January 2014 - 06:32 AM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Need help in base conversion!

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,276
  • Joined: 28-March 11

Re: Need help in base conversion!

Posted 04 January 2014 - 06:48 AM

I will be truthful, I refuse to look over your code to see where the problem is once I seen the names of the string variables knowing the rest of the code will be the same. Why in the world are all of your strings named msg with some letters and numbers appended??? That makes code so unreadable. One should be able to look at the code and be able to tell what each interrupt will print without having to scroll back to the data section. Ok, I just looked at the rest of the code... Horrible. You have labels named, msgs1, msgs4, start3, start1, and your jumping all over the place, at least break the code up into procedures and add some comments.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1