Logo 
Search:

Assembly Language Articles

Submit Article
Home » Articles » Assembly Language » Homework HelpRSS Feeds

Program to convert hexadecimal number to binary

Posted By: Helga Miller     Category: Assembly Language     Views: 13240

Write a program to convert hexadecimal number to binary.

Code for Program to convert hexadecimal number to binary in Assembly Language

DATA SEGMENT
        STR1 DB "BINARY NUMBER IS : $"
        STR2 DB "DECIMAL NUMBER IS : $"
        BSTR DB 20 DUP("$")
        RSTR DB 20 DUP("$")
        NEWLINE DB 13,10,"$"
        CNT DB 0
        N DB 2
        H DB 16
        D DB 10H
        NUM DB ?
        SNUM DB ?
        HNUM DB 19H
DATA ENDS
CODE SEGMENT
        ASSUME CS:CODE,DS:DATA 
START:
        MOV AX,DATA
        MOV DS,AX
;CONVERT HEXA TO DECIMAL

        MOV CX,00
        MOV DX,00

     L6:MOV AX,00
        MOV AL,HNUM
        DIV D
        MOV HNUM,AL
        
        MOV BX,AX
        MOV CL,CNT
        MOV AX,1
        L5: CMP CL,00
            JE L7
            MUL H
            SUB CL,1
            JMP L5    
       L7: MUL BH
        ADD DX,AX
        ADD CNT,1
        CMP HNUM,0
        JG L6
        MOV NUM,DL


;CONVERT DECIMAL TO BINARY
        LEA SI,BSTR
        LEA DI,RSTR
    L1: MOV AX,00
        MOV AL,NUM
        DIV N
        ADD AH,30H
        MOV BYTE PTR[SI],AH
        INC SI
        MOV NUM,AL
        CMP AL,0
        JG L1

        DEC SI

     L2:MOV BL,BYTE PTR[SI]
        MOV BYTE PTR[DI],BL
        DEC SI
        INC DI
        CMP SI,0
        JNE L2

        MOV AH,09H
        LEA DX,STR1
        INT 21H


        MOV AH,09H
        LEA DX,RSTR
        INT 21H


        MOV AH,4CH
        INT 21H

CODE ENDS
        END START



;------
;OUTPUT
;------

        BINARY NUMBER IS : 11001

  
Share: 


Didn't find what you were looking for? Find more on Program to convert hexadecimal number to binary Or get search suggestion and latest updates.

Helga Miller
Helga Miller author of Program to convert hexadecimal number to binary is from Frankfurt, Germany.
 
View All Articles

 

Other Interesting Articles in Assembly Language:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!