Running 2 Youtube Channel : The Masti Adda (Fun based ) : The Knowledge Adda (Knowledge based) : Subscribe for Knowledge with Fun....

Write an assembly language program to convert Hexadecimal number into equivalent ASCII number.

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program such that it can convert any given 8-bit hexadecimal number to its equivalent ASCII code. As ASCII code for 4 is 34.
Algorithm:
  • Load given data into accumulator and store it in B
  • Mask upper nibble the accumulator data
  • Call subroutine for get ASCII code for lower Nibble
  • Store it at memory location
  • Move B into Register A and mask the lower nibble.
  • Rotate upper nibble to lower nibble position.
  • Call subroutine for get ASCII code for upper Nibble
  • Store it at memory location
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
LDA
2500 H
Get hexadecimal Data
2003
MOV
B,A

2004
ANI
0F H
Mask Upper Nibble
2006
CALL
2019
ASCII Code for Upper Nibble
2009
STA
2501 H
Store Upper Nibble
200C
MOV
A,B

200D
ANI
F0 H
Mask Lower Nibble
200F
RLC

Rotate left with carry
2010
RLC


2011
RLC


2012
RLC


2013
CALL
2019
ASCII Code for lower Nibble
2016
STA
2502 H
Store lower nibble
2019
CPI
0A H
Compare data with A
201B
JC
2020
Jump if carry
201E
ADI
07 H
Add 07 to accumulator
2020
ADI
30 H
Add 30 to accumulator
2022
RET

Return unconditionally
2023
RST
5
Set Breakpoint
2024
END

End the program

Used Instruction:
LDA address: Load data into register A (accumulator) directly from the address given within the instruction.
MOV: This instruction is used to copy the content from source register to destination register.
ANI: 8-bit data logically ANDed with the content of accumulator.
CALL: Call Unconditionally
JC: Jump if carry at specified memory address.
RLC: Each binary bit of the accumulator is rotated left by one. Bit D7 is placed in the position of B0 as well as carry flag.
CPI: Compare 8-bit data with the content of accumulator.
ADI: This instruction is used to add the given content to the content of accumulator and store output in accumulator.
STA: This instruction is used to store the content of accumulator at specified memory address.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to execute the program.
Result:
Input:
2500-E4 H
Output:
2501-34 (ASCII code for 4)
2502-45 (ASCII code for E)
Procedure to look output
  • After press ENTER, You will get first screen
  • Press G and Provide Initial address (as 2000)
  • Press SHIFT+4,You will get first screen again
  • Press M and Provide Input location for Input (M2500)
  • Press ENTER and Provide your Input at location (2500:E4)
  • Press SHIFT+4
  • Press G and Provide Initial address (as 2000)
  • Press SHIFT+4,You will get first screen again
  • Press M and Provide address for output (M2501) and press ENTER
  • You will get your desired output.

2 comments:

  1. ascii code for 4 is 4 right how is it 34

    ReplyDelete
  2. ascii code for 4 is 4 right how is it 34

    ReplyDelete