8085 program to convert a hexadecimal number into ASCII code - GeeksforGeeks

26 May, 2019
Problem: Write an assembly level language program to convert HEX code to its respective ASCII code.Assume that starting address of program and input memory location are 2000 and 2050 respectively.
Example:
Input: 2050 E4 (Hex data)

Output:
2051 34 (ASCII code for 4)
2052 45 (ASCII code for E) 
Algorithm:
Load the given data in accumulator and move to B registerMask the most significant 4 bits(upper nibble) of the Hexa decimal number in accumulator.Call subroutine to get ASCII of least significant 4 bits.Store it in memoryMove B register to accumulator and mask the least significant 4 bits(lower nibble).Rotate the upper and lower nibble position.Call subroutine to get ASCII of upper nibbleStore it in memoryTerminate the program.
Load the given data in accumulator and move to B register
Mask the most significant 4 bits(upper nibble) of the Hexa decimal number in accumulator.
Call subroutine to get ASCII of least significant 4 bits.
Store it in memory
Move B register to accumulator and mask the least significant 4 bits(lower nibble).
Rotate the upper and lower nibble position.
Call subroutine to get ASCII of upper nibble
Store it in memory
Terminate the program.
Code:
Explanation:
LDA 2050H: load the content of memory location 2050H in accumulator.MOV B, A: copies the content of accumulator to register B.ANI OFH: AND operation is performed between accumulator and 0FH value.CALL SUB1: the subroutine at memory location SUB1 is called.STA 2051H: store the content of accumulator in the memory location 2051H.MOV A, B: copies the content of register B to accumulator.ANI F0H: AND operation is performed between accumulator and F0H value.RLC: rotate accumulator left.HLT: stops executing the program and halts any further execution.CPI 0AH: compare accumulator content with 0AH value.JC SKIP: jump to memory location SKIP if the carry bit is set.ADI 07H: add 07H value to the content of accumulator.RET: Return from the subroutine unconditionally.
LDA 2050H: load the content of memory location 2050H in accumulator.
MOV B, A: copies the content of accumulator to register B.
ANI OFH: AND operation is performed between accumulator and 0FH value.
CALL SUB1: the subroutine at memory location SUB1 is called.
STA 2051H: store the content of accumulator in the memory location 2051H.
MOV A, B: copies the content of register B to accumulator.
ANI F0H: AND operation is performed between accumulator and F0H value.
RLC: rotate accumulator left.
HLT: stops executing the program and halts any further execution.
CPI 0AH: compare accumulator content with 0AH value.
JC SKIP: jump to memory location SKIP if the carry bit is set.
ADI 07H: add 07H value to the content of accumulator.
RET: Return from the subroutine unconditionally.
microprocessor
system-programming
Computer Organization & Architecture
microprocessor
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Architecture of 8086
Logical and Physical Address in Operating System
Computer Organization and Architecture | Pipelining | Set 1 (Execution, Stages and Throughput)
Architecture of 8085 microprocessor
8085 program to add two 8 bit numbers
Interrupts
Memory Hierarchy Design and its Characteristics
IEEE Standard 754 Floating Point Numbers
Computer Organization | Von Neumann architecture
Difference between Von Neumann and Harvard Architecture