C34_EXP2_MP
C34_EXP2_MP
Experiment No.02
A.1 Aim: Write assembly language program to perform Hex to BCD code conversion.
A.2 Prerequisite: knowledge about Hexadecimal, BCD numbers and instruction set of 8086
A.3 Outcome:
After successful completion of this experiment students will be able to
1. Use appropriate instructions to program microprocessor to perform various
task.
2. Develop the program in assembly/ mixed language for Intel 8086 processor
3. Demonstrate the execution and debugging of assembly/ mixed language program
A.4 Theory
Theory:
Hexadecimal Number System:
The hexadecimal numeral system, often shortened to "hex", is a numeral system made up of
16 symbols (base 16). The standard numeral system is called decimal (base 10) and uses ten
symbols: 0,1,2,3,4,5,6,7,8,9. Hexadecimal uses the decimal numbers and six extra symbols.
There are no numerical symbols that represent values greater than ten, so letters taken from
the English alphabet are used, specifically A, B, C, D, E and F. Hexadecimal A = decimal 10,
and hexadecimal F = decimal 15. Being a Base-16 system, the hexadecimal numbering system
therefore uses 16 (sixteen) different digits with a combination of numbers from 0 through to 15.
In other words, there are 16 possible digit symbols.
To convert from HEX to BCD, you have to first convert the HEX to Decimal, and then
convert the Decimal digits to BCD digits, by converting each Decimal digit to 4 binary digits.
Example: convert Hex 1A2B3C to BCD.
Convert HEX 1A2B3C to Decimal and convert the decimal to BCD.
Hexa to decimal of 1A2B3C = 1715004. We have to take this as 01715004 (add a 0 to the
start) to get even number of digits. Now convert each digit to binary.
Decimal to BCD:- 01715004 = 0000 0001 0111 0001 0101 0000 0000 0100.
So Hex to BCD of 1A2B3C:- 0000 0001 0111 0001 0101 0000 0000 0100 BCD.
A.4 Algorithm
For a 4 digit Hex number whose equivalent binary number is to be found i.e. FFFF H.
Initially we compare FFFF H with decimal 10000 ( 2710 H in Hex ). If number is greater than
10,000 we add it to DH register. Also, we subtract decimal 10,000 from FFFF H, each time
comparison is made. Then we compare the number obtained in AX by 1000 decimal. Each time
we subtract 1000 decimal from AX and add 1000 decimal to BX. Then we compare number
obtained in AX by 100 decimals. Each time we subtract 100 decimal from AX and add 100
decimal to BX to obtain BCD equivalent. Then we compare number obtained in AX with 10
decimal. Each time we subtract 10 decimal from AX and we add 10 decimal to BX. Finally we
add the result in BX with remainder in AX. The final result is present in register DH with
contains the 5th bit if present and register AX.
PART B
(PART B : TO BE COMPLETED BY STUDENTS)
(Students must submit the soft copy as per following segments within two hours of the
practical. The soft copy must be uploaded at the end of the practical)
(Paste your code completed during the 2 hours of practical in the lab here)
ORG 100H
MOV AX, 1A3FH ; Hexadecimal number
HEX_TO_BCD:
JNZ HEX_TO_BCD
PRINT_BCD:
POP_LOOP:
INT 21H
Output:
(Students are expected to comment on the output obtained with clear observations and
learning for each task/ sub part assigned)
Observations:
1. The program successfully converts a hexadecimal number into its BCD
representation.
2. The DIV instruction is crucial for extracting decimal digits from a hexadecimal
number by repeatedly dividing by 10.
3. The use of stack (PUSH and POP) ensures that the BCD digits are displayed in the
correct order.
4. The TEST AX, AX instruction optimizes checking for zero, reducing unnecessary
comparisons.
5. The ASCII conversion is achieved by adding '0' (30H) to each extracted digit before
displaying it.
Learning:
• The importance of modular arithmetic in converting number bases.
• How register-based operations (AX, BX, DX) efficiently handle arithmetic in 8086.
• Stack operations can help reverse-order printing in an intuitive manner.
• DOS interrupt (INT 21H) is a simple way to display characters on the screen.
B.4 Conclusion:
(Students must write the conclusion as per the attainment of individual outcome listed
above and learning/observation noted in section B.3)
From the experiment, we have successfully converted a hexadecimal number to BCD format using
division and stack operations. This method is highly efficient and demonstrates the power of
arithmetic operations in assembly language. We learned the significance of ASCII conversion,
register-based computation, and proper stack usage to ensure correct output formatting.
This experiment reinforced the fundamental concepts of BCD encoding, arithmetic instructions, and
output display in 8086.
Q1. List out and explain BCD and ASCII Arithmetic instruction