Welcome back.
In this lesson, we are going to load certain values into -, - and -, and then switch those values
by using push and pops.
So let's load our template too first.
And now we go to
here. We modify the value - right-click here and modify and put one for -.
And now we modify the value in - - modified and put two for -.
So now your job is to write a program that will swap these values.
So how to do that?
So to swap the values, we will push - to the stack first.
So we type push - and push -.
All right, let's run our program and step over.
All right.
So this is being overwritten because we execute this.
So let's put back the value one here and two over here.
All right.
So now we have one and two.
What you want to do is swap this.
So to do that, we have to push this to the stack.
First, push one to the stack and then push two to the stack.
So now if you want to swap these values, what we need to do is we need to pop.
We need to pop - first.
That means we pop two to -.
So we pop -.
Now we run.
The command - now became two because it popped the two from the top of the stack into -.
Then we pop this into -.
So now we do pop -.
And if you step away now, - became one.
So you see, this is how we can use the stack to switch the values in the registers.
So you notice here we push and pop in the same order - -.
And we also pop same order - -.
So when you do stuff like this, it means that you are swapping values.
So if you wanted to preserve the original value, then you should pop in the reverse order like pop
- first and then -.
So that's all for this video.
Thank you for watching.