0
(0)

[PRACTICAL] IMPLEMENT A PROGRAM TO REVERSE A STRING USING STACK OPERATIONS AND STORED IN SAME MEMORY AREA

Are you looking for a step-by-step guide to Implement a program to reverse a string using stack operations and stored in same memory area? here are the steps to implement a program to reverse a string using stack operations and stored in same memory area.

Theory:

This program used stack related instruction i.e. push and pop to reverse given string. To implement program first we take array of 10 elements and store it in location C050h, and used loop for 5 times.in each loop PUSH instruction push content from to continuous memory location to the top of the stack. After push operation content of memory location is pop using POP instruction from top of the stack. Because of LIFO nature of stack last element POP first so that we can pop from stack and store on same memory location at C050h. after all POP operation we can get string in reverse in the same memory location.  

Program:

LXI H,C050H 
MVI C,05H
NEXT: MOV D,M
INX H
MOV E,M
INX H
PUSH D
DCR C
JNZ NEXT
LXI H,C050H 
MVI C,05H
NEXT1: POP D
MOV M,E
INX H
MOV M,D
INX H
DCR C
JNZ NEXT1
HLT

INPUT:

OUTPUT:

For more practical related to 885 Programming please visit the 8085 Programming link

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Share this post on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?