0% found this document useful (0 votes)
9 views12 pages

Experiment 13: To Convert Given Hexa Decimal Number Into Its Equivalent BCD Number Using 8085 Instructions Set

The document describes experiments using the 8085 microprocessor to convert hexadecimal numbers into Binary Coded Decimal (BCD) and ASCII formats, as well as to sort an array using the bubble sort algorithm. Each experiment includes required apparatus, theory, algorithms, programs, flowcharts, and results. The experiments demonstrate the practical application of the 8085 instruction set for data conversion and sorting tasks.

Uploaded by

iiitbdiaries11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Experiment 13: To Convert Given Hexa Decimal Number Into Its Equivalent BCD Number Using 8085 Instructions Set

The document describes experiments using the 8085 microprocessor to convert hexadecimal numbers into Binary Coded Decimal (BCD) and ASCII formats, as well as to sort an array using the bubble sort algorithm. Each experiment includes required apparatus, theory, algorithms, programs, flowcharts, and results. The experiments demonstrate the practical application of the 8085 instruction set for data conversion and sorting tasks.

Uploaded by

iiitbdiaries11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Experiment 13: To convert given Hexa decimal number into its

equivalent BCD number using 8085 instructions set

Apparatus Required:
 8085 Microprocessor Kit / GNU Sim8085
 Personal Computer (for simulation)
 Assembler and Emulator
 Power Supply

Theory:
In this experiment, the hexadecimal number is first loaded from memory and
treated as a loop counter. A value of 10H (16 in decimal) is repeatedly added to the
accumulator as many times as the value of the input. After each addition, the DAA
(Decimal Adjust Accumulator) instruction is used to adjust the binary result into a
valid BCD format. If the addition results in a carry, it indicates that the BCD count
has exceeded one byte, so the higher byte (stored in register D) is incremented.
This process continues until the loop counter reaches zero.
At the end of the program, the lower byte of the BCD result (LSB) is stored in
memory from the accumulator, and the higher byte (MSB) is stored from register
D. This method ensures accurate conversion of any 8-bit hexadecimal number
(00H to FFH) into its correct BCD representation using the 8085-instruction set
and the GNUSim8085 simulator.

Algorithm:
1. Initialize memory pointer to 4150H (location where HEX input is stored).
2. Clear register D (for MSB of BCD result).
3. Clear the accumulator using XRA A.
4. Load HEX value from memory into register C (counter).
5. Repeat the following steps C times:
o Add 10H to accumulator.
o Apply DAA to convert result to valid BCD.
o If carry occurs, increment register D.
6. After the loop ends:
o Store the contents of A (LSB) to memory location 4151H.
o Store the contents of D (MSB) to memory location 4152H.
7. End the program.

Program:
LXI H, 4150H ; Initialize memory pointer
MVI D, 00H ; Clear D-register (MSB of result)
XRA A ; Clear Accumulator
MOV C, M ; Get HEX data into register C

LOOP2: ADI 10H ; Add 16 (decimal) to accumulator


DAA ; Adjust for BCD
JNC LOOP1 ; If no carry, skip incrementing D
INR D ; If carry, increment D

LOOP1: DCR C ; Decrement counter


JNZ LOOP2 ; Loop until counter becomes zero

STA 4151H ; Store LSB of BCD result


MOV A, D ; Move MSB into accumulator
STA 4152H ; Store MSB of BCD result
HLT ; Halt the program

Flowchart:
Start

Load HEX input from 4150H into register C

Clear accumulator (A)

Clear register D (MSB of BCD result)

Start loop:

Add 10H to accumulator

Use DAA instruction to adjust to BCD

If carry, increment register D

Decrement register C

If C ≠ 0, repeat loop

Store accumulator (A) to 4151H (LSB)

Store register D to 4152H (MSB)

End

Output:

Fig: 13.1

Result/Conclusion:
The program successfully converts a given Hexadecimal number into its Binary
Coded Decimal (BCD) equivalent using the 8085 instruction set. By performing
repeated addition and using the DAA (Decimal Adjust Accumulator) instruction,
the hexadecimal input was accurately converted into its BCD form, with the LSB
and MSB of the result stored separately in memory.
Experiment 14: To convert given Hexa decimal number into its equivalent
ASCII number using 8085 instructions set.

Apparatus Required:
 8085 Microprocessor Kit / GNU Sim8085
 Personal Computer (for simulation)
 Assembler and Emulator
 Power Supply

Theory: The process of converting a hexadecimal number to its equivalent ASCII


code involves mapping each individual hex digit (0-9, A-F) to its corresponding
ASCII value. In the ASCII encoding scheme, the numeric values 0 through 9 are
represented by the codes 30H to 39H, while the alphabetic values A through F are
represented by the ASCII codes 41H to 46H. The hexadecimal number is
composed of two nibbles: the upper nibble (higher 4 bits) and the lower nibble
(lower 4 bits). To convert these to ASCII, we first check whether each nibble is in
the range of 0–9 or A–F. If the nibble is a numeric value (0–9), we simply add 30H
to it. If the nibble is an alphabetic value (A–F), we add 41H. The program works
by loading the hexadecimal number into the A-register, masking and processing the
nibbles, and calling subroutines to convert each nibble to its corresponding ASCII
value. The results are then stored in memory for further use or display. This
process enables the conversion of hexadecimal digits to their printable ASCII
representations, which are commonly used for display on devices like LCDs or in
communication protocols.

Algorithm:
1. Load the given hexadecimal data into the A-register and move it to the B-
register.
2. Mask the upper nibble of the hexadecimal number in the A-register.
3. Call a subroutine to convert the lower nibble to its ASCII equivalent.
4. Store the resulting ASCII value in memory.
5. Move the B-register to the A-register and mask the lower nibble.
6. Rotate the upper nibble to the lower nibble position.
7. Call a subroutine to convert the upper nibble to its ASCII equivalent.
8. Store the resulting ASCII value in memory.
9. End the program.

Program:
LDA 4200H ; Load HEX data from memory (4200H)
MOV B, A ; Move the HEX data to B-register
ANI 0F ; Mask the upper nibble
CALL SUB1 ; Convert the lower nibble to ASCII
STA 4201H ; Store ASCII of lower nibble in memory
MOV A, B ; Move B-register back to A-register
ANI 0F ; Mask the lower nibble
RLC ; Rotate the upper nibble to the lower nibble position
CALL SUB1 ; Convert the upper nibble to ASCII
STA 4202H ; Store ASCII of upper nibble in memory
HLT ; End the program

; Subroutine to convert nibble to ASCII


SUB1: CPI 0A ; Compare with 10 (decimal)
JC SKIP ; If less than 10, jump to SKIP
ADI 07H
SKIP: ADI 30H ; Add 30H to get ASCII code
RET ; Return from subroutine

Flowchart: Start

Load HEX input into A-register

Move HEX data to B-register

Mask upper nibble in A-register

Call subroutine to convert lower nibble to ASCII

Store ASCII of lower nibble in memory

Move B-register back to A-register

Mask lower nibble in A-register

Rotate upper nibble to lower nibble position

Call subroutine to convert upper nibble to ASCII

Store ASCII of upper nibble in memory

End
Output:

Fig: 14.1

Result/Conclusion:
The program effectively converts a given hexadecimal number into its equivalent
ASCII codes. By processing each nibble of the hexadecimal input and converting it
using simple arithmetic, the program successfully outputs the corresponding ASCII
values. This experiment demonstrates the use of the 8085-microprocessor
instruction set to perform basic data conversion tasks.

---------------------------END OF EXPERIMENT-----------------------------
Experiment 15: To write a program to arrange an array of data in
ascending order using 8085 microprocessor

Apparatus Required:
 8085 Microprocessor Kit / GNU Sim8085
 Personal Computer (for simulation)
 Assembler and Emulator
 Power Supply

Theory:
This program uses the bubble sort algorithm to arrange the array of numbers in
ascending order. In bubble sort, the algorithm makes multiple passes through the
list, comparing adjacent elements and swapping them if they are in the wrong
order. After each pass, the largest element is "bubbled" to the end of the array. The
process is repeated until the entire array is sorted. In this program, the array size is
stored at 4200H, and the array elements begin at 4201H.

Algorithm:
1. Initialize HL pair as the memory pointer.
2. Load the count (size of the array) from memory location 4200H into the C-
register.
3. Copy the count from the C-register to the D-register (this is used for bubble
sort, as N-1 iterations are needed).
4. Get the first value of the array into the A-register.
5. Compare the value in the A-register with the value in the next memory location.
6. If the values are out of order, exchange the contents of the A-register and the
value in memory.
7. Decrement the D-register by 1.
8. Repeat steps 5-7 until the value in the D-register becomes 0.
9. Decrement the C-register by 1.
10.Repeat steps 3-9 until the value in the C-register becomes 0.

Program:
REPEAT: LXI H, 4200
MOV C, M
MOV D, C
LXI H, 4201

LOOP: MOV A, M
INX H
CMP M
JC SKIP
MOV B, M
MOV M, A
DCX H
MOV M, B
INX H

SKIP: DCR D
JNZ LOOP
DCR C
JNZ REPEAT
HLT
Flowchart:
Start

Load array size from 4200H into C

Copy C into D

Point HL to 4201H (start of array)

Load value into A

Compare with next value

If A > next → Swap

Decrement D

If D ≠ 0 → Repeat comparison loop

Decrement C

If C ≠ 0 → Repeat outer loop

Stop
Output:

Fig: 15.1

BEFORE SORTING

Fig: 15.2

AFTER SORTING

Result/Conclusion:
The program successfully arranged the given array in ascending order using the
bubble sort technique. By repeatedly comparing and swapping adjacent elements,
the largest values moved to the end in each pass. The use of 8085 instructions
demonstrated how sorting can be implemented at the assembly level efficiently.

You might also like