0% found this document useful (0 votes)
12 views6 pages

C34_EXP2_MP

The document outlines an experiment aimed at teaching students to write an assembly language program for converting hexadecimal numbers to BCD format using the Intel 8086 processor. It includes theoretical background on hexadecimal and BCD systems, an algorithm for conversion, and a sample code implementation. Students are expected to document their observations, learning outcomes, and conclusions after completing the experiment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

C34_EXP2_MP

The document outlines an experiment aimed at teaching students to write an assembly language program for converting hexadecimal numbers to BCD format using the Intel 8086 processor. It includes theoretical background on hexadecimal and BCD systems, an algorithm for conversion, and a sample code implementation. Students are expected to document their observations, learning outcomes, and conclusions after completing the experiment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

PART A

(PART A : TO BE REFFERED BY STUDENTS)

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.

Binary-Coded Decimal (BCD)


A binary-coded decimal (BCD) is a type of binary representation for decimal values where
each digit is represented by a fixed number of binary bits, usually between four and eight.The
norm is four bits, which effectively represent decimal values 0 to 9. This writing format system
is used because there is no limit to the size of a number. Four bits can simply be added as
another decimal digit, versus real binary representation, which is limited to the usual powers
of two, such as 16, 32 or 64 bits.

The following are the 4-bit binary representation of decimal values:


0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101
6 = 0110
7 = 0111
8 = 1000
9 = 1001

Example of Hexadecimal to BCD:

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)

Roll. No:34 Name: Shrinath Babar

Class: SE-C-COMPS Batch:C2


Date of Experiment: Date of Submission:
Grade:

B.1 Software Code written by student:

(Paste your code completed during the 2 hours of practical in the lab here)

ORG 100H
MOV AX, 1A3FH ; Hexadecimal number

MOV BX, 10 ; Decimal base

MOV CX, 0 ; Digit counter

HEX_TO_BCD:

XOR DX, DX ; Clear DX

DIV BX ; AX / 10 → Quotient in AX, Remainder in DX

ADD DL, '0' ; Convert remainder to ASCII

PUSH DX ; Store ASCII digit

INC CX ; Count digits

TEST AX, AX ; Check if quotient is zero

JNZ HEX_TO_BCD

PRINT_BCD:

MOV AH, 02H ; DOS print character

POP_LOOP:

POP DX ; Get ASCII digit

INT 21H ; Print it

LOOP POP_LOOP ; Repeat until all digits are printed

MOV AH, 4CH ; Exit program

INT 21H

B.2 Input and Output:


Input:

Output:

B.3 Observations and learning:

(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.

B.5 Question of Curiosity

Q1. List out and explain BCD and ASCII Arithmetic instruction

1. BCD Arithmetic Instructions


BCD operations are used for decimal-based calculations where each digit is stored in 4 bits.
Instruction Description
DAA (Decimal Adjust after Converts the result of a BCD addition into a valid BCD
Addition) form. Used after ADD instruction.
DAS (Decimal Adjust after Adjusts the result of a BCD subtraction. Used after SUB
Subtraction) instruction.
AAM (ASCII Adjust after
Converts the result of MUL to unpacked BCD.
Multiplication)
AAD (ASCII Adjust before Converts unpacked BCD to a binary number before
Division) division.
2. ASCII Arithmetic Instructions
ASCII arithmetic is used when performing operations on ASCII-coded numbers (0x30 -
0x39).
Instruction Description
AAA (ASCII Adjust after Converts the result of adding two ASCII numbers into a
Addition) valid ASCII form.
AAS (ASCII Adjust after
Adjusts the result after subtracting ASCII numbers.
Subtraction)

You might also like