WEBVTT

1
00:00.920 --> 00:01.820
Welcome back.

2
00:01.820 --> 00:10.070
In this lesson, we are going to load certain values into -, - and -, and then switch those values

3
00:10.070 --> 00:11.660
by using push and pops.

4
00:11.660 --> 00:14.000
So let's load our template too first.

5
00:15.200 --> 00:17.510
And now we go to

6
00:17.510 --> 00:26.630
here. We modify the value - right-click here and modify and put one for -.

7
00:27.680 --> 00:32.810
And now we modify the value in - - modified and put two for -.

8
00:33.860 --> 00:38.090
So now your job is to write a program that will swap these values.

9
00:38.480 --> 00:39.620
So how to do that?

10
00:39.830 --> 00:44.300
So to swap the values, we will push - to the stack first.

11
00:44.300 --> 00:51.050
So we type push - and push -.

12
00:52.400 --> 00:55.040
All right, let's run our program and step over.

13
00:57.660 --> 00:57.960
All right.

14
00:57.960 --> 01:01.500
So this is being overwritten because we execute this.

15
01:01.500 --> 01:08.610
So let's put back the value one here and two over here.

16
01:10.960 --> 01:11.230
All right.

17
01:11.230 --> 01:12.550
So now we have one and two.

18
01:12.580 --> 01:15.010
What you want to do is swap this.

19
01:15.010 --> 01:17.950
So to do that, we have to push this to the stack.

20
01:17.950 --> 01:23.890
First, push one to the stack and then push two to the stack.

21
01:24.310 --> 01:28.510
So now if you want to swap these values, what we need to do is we need to pop.

22
01:29.740 --> 01:31.750
We need to pop - first.

23
01:31.900 --> 01:34.360
That means we pop two to -.

24
01:34.960 --> 01:39.010
So we pop -.

25
01:40.420 --> 01:41.170
Now we run.

26
01:41.170 --> 01:46.870
The command - now became two because it popped the two from the top of the stack into -.

27
01:47.050 --> 01:50.230
Then we pop this into -.

28
01:50.380 --> 01:53.230
So now we do pop -.

29
01:56.030 --> 01:59.150
And if you step away now, - became one.

30
01:59.300 --> 02:06.860
So you see, this is how we can use the stack to switch the values in the registers.

31
02:07.010 --> 02:12.560
So you notice here we push and pop in the same order - -.

32
02:12.710 --> 02:15.140
And we also pop same order - -.

33
02:15.560 --> 02:19.010
So when you do stuff like this, it means that you are swapping values.

34
02:19.430 --> 02:26.060
So if you wanted to preserve the original value, then you should pop in the reverse order like pop

35
02:26.060 --> 02:27.830
- first and then -.

36
02:27.950 --> 02:30.080
So that's all for this video.

37
02:30.080 --> 02:31.340
Thank you for watching.