Experiment 13: To Convert Given Hexa Decimal Number Into Its Equivalent BCD Number Using 8085 Instructions Set
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
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
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
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.