Share with others

BCD to Hex Conversion in Assembly Language

Write a Program For BCD to Hex Conversion in Assembly language . 
We are given a five digit BCD number whose HEX equivalent is to be found i.e. 65535 whose HEX equivalent is to be found. First we will find the Hex equivalent of 60,000. We will compare 60,000H with 10,000H. Each time we compare a counter is decremented by 10,000 and we add 10,000 decimal (2710 Hex). Then we will find the equivalent of 5000. Now we will compare 5000H with 1000H. Each time we compare the counter decrements by 1000 and we add 1000 decimal (3E8 H). Then we find the equivalent of 500H by comparing it with 100H. Each time counter decrements by 100 and we add decimal 100 (64 H). Then we find equivalent of 30H by comparing it with 10H. Each time counter decrements by 10 and we add 10 decimal (0A H). Then, equivalent of 5 is 5H.
Finally, all the equivalents obtained are added to get the equivalent of 65535.

Algorithm For BCD to Hex Conversion

Step I              :   Initialize the data segment.
Step II            :   Load the MSB of word in register AX.
Step III           :   Compare it with 0, if zero goto step VII else goto step IV.
Step IV           :   decrement AX and initialize BX = 0000.
Step V             :   add 10000 decimal to BX.
Step VI           :   Jump to step III.
Step VII         :   Load LSB of word in register AX.
Step VIII        :   Compare it with 1000, if below go to step XII else go to step IX.
Step IX           :   subtract 1000 H from AX.
Step X            :   Add 1000 decimal to BX.
Step XI           :   Jump to step VIII
Step XII         :   Compare number in AX now with 100 H, if below go to step XVI, else go to step XIII.
Step XIII       :   Subtract 100 H from AX.
Step XIV        :   Add 100 decimal to BX.
Step XV         :   Jump to step XII.
Step XVI        :   Compare number in AX with 10H, if below go to step XX, else go to step XVII.
Step XVII      :   Subtract 10 H from AX
Step XVIII    :   Add 10 decimal to BX
Step XIX       :   Jump to step XVI
Step XX         :   Add contents of AX and BX.
Step XXI       :   Display the result.
Step XXII      :   Stop.

Program For BCD to Hex Conversion Code

How to Run this Program

For Running this program you should have installed Tasm on you computer . If you have not installed Tasm  yet please install from Here .


C:\programs>tasm bcd2hex.asm
Turbo Assembler  Version 3.0  Copyright (c) 1988, 1991 Borland International
Assembling file:   bcd2hex.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  437k
C:\programs>tlink bcd2hex
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International


Share with others