In this video, let's discuss some most commonly used stack instructions.
Let's begin by writing a simple program.
I'm going to create a new file called Push, Flash, Pop, not Nazim.
And as usual, I'm going to start with a global directive, so let's type global space and let's start
and let's specify this start as our entry point here and let's first write the instruction, move our
eggs, comma 20.
Next, let's push the value stored in this register under the stack by using the instruction push at
X.
So I'm typing push out X, let's push the value stored in the register under the stack.
Once again I'm typing push out X and then let's use pop idea.
What this instruction will do is whatever the value that we have recently pushed onto the stack will
be popped into the idea register.
Now let's also type pop RB X.
This time the value on the top of the stack will be popped into the register.
RB X.
Now let's save the file and let's once again assemble and link it.
Nazem pushpa dot nazeem dash o push pop dot o f l sixty four and let's say early push pop dot o bargepole
push nasch pop.
So that's going to be our output file.
Now let's open it up using GDP.
I'm typing gdb dot slash, push, dash, pop and let's set up an entry point at underscore start and
let's run it.
Here we are.
This is the disassembly and observe what we have on the top of the stack.
At this point of time we have value one on the top of the stack.
Now let's type say to move the value hex falling into X.
I'm typing s.A.
As you can see here, the register adex contains the value hex 14 now still the top of the stack contains
value one.
And we are about to push the value that is stored in order to register onto the stack.
So once this instruction gets executed, the value that is currently stored in our eggs will be pushed
onto the stack.
So let's take a say.
And as you can see now, the top of the stack is pointing to the value hex 14.
Now, the next instruction to be executed is one more push IREX.
That means we should see another similar entry on the stack now.
So let's step aside a look at that push.
IREX instruction has pushed the value HEX 14 onto the stack once again.
Now the next instruction to be executed is pop idea.
Pop is one instruction that people always get confused about.
So try to put some attention here.
When you execute pop space aspecific register, what happens is whatever the value that we have on the
top of the stack is going to be popped into the register.
In this case, the register idea is going to contain the value hex 14 because that's the value that
is on the top of the stack.
So let's execute this idea before executing that.
Let's quickly check the value that we currently have in our day register.
If you notice, it's zero.
So after executing this instruction, we should see the value hex 14 in the register idei.
So let's say.
And check the value of our register, if you look at this, the register ardia contains Heggs 14 this
time.
So that's how pop instruction works.
Now, look at that.
We have another pop instruction now.
This time the value on the top of the stack is going to be popped into our vic's register.
So let's step aside and check what happened to the RBA register before that.
Once again, let's quickly check the current value of RB X register.
It's currently zero.
So let's take aside.
And once again, let's go back and check our bags and look at that, the value X 14 is popped into our
vehicles registered.
This is how push and pop instructions.
What?