8086 program to reverse a string
Problem: Given a string we have to reverse the string and print the reversed string.
Input: String : "This is a sample string" Output: gnirts elpmas a si sihT Input: String : "Geeks for Geeks" Output: skeeG rof skeeG
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Create a string
- Traverse through the string
- Push the characters in the stack
- Count the number of characters
- Load the starting address of the string
- POP the top character of the stack until count is not equal to zero
- Put the character and reduce the count and increase the address
- Continue until the count is greater than zero
- Load the effective address of the string in dx using LEA command
- Print the sting by calling the interrupt with 9H in AH
- The string must be terminated by ‘$’ sign
gnirts elpmas a si sihT
The program cannot be run on an online editor, please use MASM to run the program and use dos box to run MASM, you might use any 8086 emulator to run the program.