Problem – Write an assembly level language program to convert ASCII code to its respective HEX Code.
Examples:
Input:
DATA: 31H in memory location 2050
Output:
DATA: 0BH in memory location 3050
Assume that starting address of program, input memory location, and output memory locations are 2000, 2050, and 3050 respectively.
Algorithm –
- Input the content of 2050 in accumulator.
- Subtract 30H from accumulator.
- Compare the content of accumulator with 0AH.
- If content of accumulator is less than 0A then goto step 6 else goto step 5.
- Subtract 07H from accumulator.
- Store content of accumulator to memory location 3050.
- Terminate the program.
Program –
ADDRESS |
MNEMONICS |
COMMENTS |
2000 |
LDA 2050 |
A<-[2050] |
2003 |
SUI 30H |
A<-A-30 |
2005 |
CPI 0AH |
|
2007 |
JC 200D |
Check for carry |
200B |
SUI 07H |
A<-A-07H |
200D |
STA 3050 |
[3050]<-A |
2010 |
HLT |
Stop execution |
Explanation –
- LDA 2050 load the content of memory location 2050 to accumulator.
- SUI 30H subtracts 30H immediately from accumulator.
- CPI 0AH compare immediately 0AH with the data of accumulator.
- JC 200D check for carry if yes then go to address 200D.
- SUI 07H subtracts 07H immediately from accumulator.
- STA 3050 store the content of accumulator to memory location 3050.
- HLT stops the execution of program.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
14 Jun, 2018
Like Article
Save Article