Programs Experts Community Question Online Exam ResourceLink Gallery Members Search
Login
Username:
Password:
New user? Sign up
Forgot Password?
Notice
New Category Started

Question, Resource &
Rich Text Editor
for content text input
Invite Friends
Email *
Firstname *
Lastname
 
Programmer Information
View Source Code
hex to bcd program 8086(masm) by hitesh g
PRINT MACRO MSG
    MOV AH,09H
    LEA DX,MSG
    INT 21H
ENDM

CHAR MACRO
    ADD AL,30H
    MOV AH,02H
    MOV DL,AL
    INT 21H
ENDM


DATA  SEGMENT
    HEX DW ?
    BCD DW ?
    ARRAY DW 09H DUP(?)
    MSG11 DB 10,13,"ENTER 5 DIGIT NO. :$"
    MSG DB 10,13,"ENTER 4 DIGIT HEX NO. :$"
    MSG2 DB 10,13,"EQUIVALENT HEX IS :$"
    PRG DB 10,13,"      -: PROGRAM FOR CODE CONVERSION :-$"
    HBC DB 10,13,"        1.HEX TO BCD $"
    BHC DB 10,13,"        2.BCD TO HEX $"
    EX DB 10,13,"        3.EXIT $"
    CHOICE DB 10,13,"ENTER YOUR CHOICE :$"
    CHS DB ?
    MSG1 DB 10,13,"EQUIVALENT BCD IS :$"

DATA ENDS
CODE SEGMENT
    ASSUME DS:DATA,CS:CODE
    START :
        MOV AX,DATA
        MOV DS,AX
        PQR:
            PRINT PRG
            PRINT HBC
            PRINT BHC
            PRINT EX
            PRINT CHOICE

            MOV AH,01H
            INT 21H

            CMP AL,39H
            JBE B
            SUB AL,07H
            B:
                SUB AL,30H

            MOV CHS,AL

            CMP AL,01H
            JE HTOB
            CMP AL,02H
            JE BTOH
            CMP AL,03H
            JE ABC
            HTOB :
                CALL HXBCD
            JMP PQR
            BTOH :    
                CALL BCDHX
            JMP PQR
            ABC:
                MOV AH,04CH
                INT 21H
        

HXBCD PROC

    PRINT MSG
    CALL ACCEPT
    MOV CH,AL
    CALL ACCEPT
    MOV CL,AL
    MOV HEX,CX

    PRINT MSG1

    MOV AX,HEX
    MOV DX,0000H
    MOV CX,2710H

    DIV CX
    MOV HEX,DX

    CHAR


    MOV AX,HEX
    MOV DX,0000H
    MOV CX,03E8H

    DIV CX

    MOV HEX,DX
    CHAR
    
    
    MOV AX,HEX
    MOV CL,64H

    DIV CL

    MOV BH,00H
    MOV BL,AH
    MOV HEX,BX
    
    CHAR


    MOV AX,HEX
    MOV CL,0AH
    DIV CL

    MOV BL,AH

    CHAR


    MOV AL,BL

    CHAR


    RET
HXBCD ENDP


ACCEPT PROC
    MOV AH,01H
    INT 21H
    CMP AL,39H
    JBE BELOW1
    SUB AL,07H
    BELOW1 :
        SUB AL,30H
    MOV CL,04H
    ROL AL,CL
    MOV BL,AL

    MOV AH,01H
    INT 21H
    CMP AL,39H
    JBE BELOW2
    SUB AL,07H
    BELOW2:
        SUB AL,30H
    ADD AL,BL
     RET
ACCEPT ENDP

DIGIT PROC
    MOV AH,01H
    INT 21H
    CMP AL,39H
    SUB AL,30H
    RET
DIGIT ENDP

BCDHX PROC
    LEA SI,ARRAY
    PRINT MSG11
    CALL DIGIT
    MOV AH,00H
    MOV DX,0000H
    MOV CX,10000

    MUL CX
    MOV WORD PTR[SI],AX
    INC SI
    INC SI

    CALL DIGIT
    MOV AH,00H
    MOV DX,0000H
    MOV CX,03E8H

    MUL CX
    MOV WORD PTR[SI],AX
    INC SI
    INC SI

    CALL DIGIT
    MOV AH,00H
    MOV DX,0000H
    MOV CX,0064H

    MUL CX
    MOV WORD PTR[SI],AX
    INC SI
    INC SI

    CALL DIGIT
    MOV AH,00H
    MOV DX,0000H
    MOV CX,000AH

    MUL CX
    MOV WORD PTR[SI],AX
    INC SI
    INC SI
    CALL DIGIT

    MOV AH,00H
    MOV DX,0000H
    MOV CX,0001H

    MUL CX
    MOV WORD PTR[SI],AX
    INC SI
    INC SI

    PRINT MSG2
    MOV AX,0000H
    LEA SI,ARRAY
    
    MOV CL,05H
    REPEAT:
        ADD AX,WORD PTR[SI]
        INC SI
        INC SI
        DEC CL

    JNZ REPEAT
    MOV BCD,AX

    MOV AL,AH
    CALL DISPLAY
    MOV AX,BCD

    CALL DISPLAY
    RET
BCDHX ENDP

DISPLAY PROC
    MOV BL,AL
    AND AL,0F0H
    MOV CL,04H
    ROR AL,CL
    CMP AL,09H
    JBE BB
    ADD AL,07H
           BB :ADD AL,30H

    MOV AH,02H
    MOV DL,AL
    INT 21H

    MOV AL,BL
    AND AL,0FH

    CMP AL,09H
    JBE B1
    ADD AL,07H
             B1 :ADD AL,30H

    MOV AH,02H
    MOV DL,AL
    INT 21H

RET
DISPLAY ENDP

CODE ENDS
END START
Views
11

Rating
0

Language
Any with Regex support

Category
Basics

Compiler
TASM

OS
Any

Last Modified
23rd Aug 10 08:55:53 PM

View Program Documentation
Rating, Comments, Suggestions & Bugs
Additional Feaures

 
© Scodz, 2006 All Rights Reserved. Guest Book | FAQ | Privacy Policy | Terms & Conditions | Contact Us  
Contact Us for Advertising in this website