1 00:00:00,150 --> 00:00:08,000 So guys in the studio, we are going to see another important topic called Stack and Stuckey's refolded 2 00:00:08,070 --> 00:00:11,430 are structure stands, transfer to foster data structure. 3 00:00:11,760 --> 00:00:17,820 It means that when you're in certain elements into the stack and it will be the last element you need 4 00:00:17,820 --> 00:00:20,120 to take back from the stack. 5 00:00:20,730 --> 00:00:23,070 The example for the stack is stack of books. 6 00:00:23,730 --> 00:00:30,660 So in this example, let's you have a table and you have 10 books and you will place the books one one 7 00:00:30,660 --> 00:00:32,250 by one on the top of each other. 8 00:00:32,670 --> 00:00:35,590 So you'll play the first book on top of the first book. 9 00:00:35,610 --> 00:00:36,690 You play the second book. 10 00:00:37,050 --> 00:00:43,730 And on the top of the second book, you play the third book and so on, on top of the ninth president. 11 00:00:43,750 --> 00:00:50,720 And so in order to take the books, you need to first take the to write. 12 00:00:50,760 --> 00:00:52,440 You cannot take from sideways. 13 00:00:52,950 --> 00:00:55,400 You only need to take from the top. 14 00:00:55,420 --> 00:01:02,940 So that means you need to take the first and the book and then the ninth book and then eight and so 15 00:01:02,940 --> 00:01:05,240 on a per second book. 16 00:01:05,250 --> 00:01:08,740 And finally the last book will be the first book. 17 00:01:10,140 --> 00:01:14,340 So this behavior is called Ashton Foster. 18 00:01:14,550 --> 00:01:17,310 That's very striking correlation, foster data structure. 19 00:01:17,670 --> 00:01:22,020 And also we can only perform two operations on the stack. 20 00:01:22,590 --> 00:01:26,190 Those operations are called push and pop operations. 21 00:01:26,700 --> 00:01:34,200 Push operation can be construed as placing the book on the table and pop operation can be considered 22 00:01:34,200 --> 00:01:37,370 as taking the book from the stack of books. 23 00:01:38,400 --> 00:01:45,540 So pushing means pushing an element to the stack and taking the top of the element furniture. 24 00:01:46,110 --> 00:01:53,080 So this Abipon and E.S.P are registers are not covering in the resistance will go. 25 00:01:53,160 --> 00:01:54,510 No, I'm going to cover this. 26 00:01:55,890 --> 00:02:01,070 EVP is called Base Pointer and EVP points to the base of this time frame. 27 00:02:01,530 --> 00:02:09,660 It means that EVP points to the starting of the political spectrum and E.S.P, which is the stack pointer 28 00:02:10,020 --> 00:02:11,740 points to the top of the spectrum. 29 00:02:11,760 --> 00:02:18,770 So if you keep on pushing the elements out of the stack, then E.S.P will point to the top of the top 30 00:02:18,840 --> 00:02:19,930 element of the stack frame. 31 00:02:20,730 --> 00:02:23,870 So if you if this sounds confusing, don't worry. 32 00:02:23,870 --> 00:02:27,110 I will I will be showing some diagrams now. 33 00:02:28,860 --> 00:02:31,970 Now, let's consider these two instructions. 34 00:02:32,280 --> 00:02:34,130 Firstly, the push SBP. 35 00:02:35,220 --> 00:02:38,520 So actually this is called the function prodrug. 36 00:02:39,240 --> 00:02:45,280 It means that whenever there is a new function in any other language like C, then a new style frame 37 00:02:45,360 --> 00:02:47,460 is created for that particular function. 38 00:02:48,510 --> 00:02:57,270 And whenever that function has been written or exited, then this time frame gets collapse. 39 00:02:58,320 --> 00:03:03,720 So this is the function product and this creates a new structure. 40 00:03:05,550 --> 00:03:13,740 And this does by pushing that SBP, which is the previous function stack frame, and this value gets 41 00:03:13,740 --> 00:03:14,700 pushed out of the stack. 42 00:03:14,730 --> 00:03:22,020 Now you can see Push EVP has been executed and the theory will be this points to the this function stack 43 00:03:22,020 --> 00:03:26,470 from previous functions and more will become ISP. 44 00:03:26,490 --> 00:03:33,480 So we are moving the E.S.P value to the IP so that these Google points to the base of the stack. 45 00:03:33,750 --> 00:03:35,070 That is the beginning of the stack. 46 00:03:35,730 --> 00:03:43,740 So these two instructions need to coordinate assembly, but because we will be coding and programming 47 00:03:43,740 --> 00:03:44,710 that start function. 48 00:03:45,000 --> 00:03:46,870 So I wetering this concept. 49 00:03:48,870 --> 00:03:52,980 So our START premise created no E.S.P. 50 00:03:52,980 --> 00:03:56,570 EBP both points to the starting of the stack. 51 00:03:56,820 --> 00:03:58,110 There are no elements. 52 00:03:58,680 --> 00:04:03,060 And from this address, four two three one four eight four, our stack begins. 53 00:04:03,600 --> 00:04:05,640 This is the third SBP address. 54 00:04:06,330 --> 00:04:08,970 Not what I'm going to do is I'm going to push an element. 55 00:04:10,020 --> 00:04:13,060 Let's say I want to push the value. 56 00:04:13,680 --> 00:04:22,080 So this file will be placed on the top of the stack and E.S.P points to this top are the top element, 57 00:04:22,080 --> 00:04:25,410 which is fine, as you can see us now. 58 00:04:25,530 --> 00:04:27,000 Not disastrous for it. 59 00:04:27,000 --> 00:04:30,840 Two three one four eight eight and disorder's eight four eight eight eight four. 60 00:04:31,230 --> 00:04:35,080 So the stack grows from I remember I remember that. 61 00:04:35,090 --> 00:04:36,650 I still remember memory address. 62 00:04:38,310 --> 00:04:46,110 And whenever you push an element out of the stack, you can see the E.S.P decrements by four by four 63 00:04:46,110 --> 00:04:55,410 bytes, because in that little bit we generally push the 32 bit value so that it means the forward so 64 00:04:55,470 --> 00:04:57,000 normal push operation. 65 00:04:57,420 --> 00:04:59,530 Operation Decrements, the. 66 00:04:59,730 --> 00:05:09,300 E.S.P by four points, and if I want to push another element, let's push Dirac's seven, then that 67 00:05:09,300 --> 00:05:16,110 value will be pushed onto the start again E.S.P decrements before and points to the top of the stack, 68 00:05:16,110 --> 00:05:16,830 which is seven. 69 00:05:18,210 --> 00:05:29,280 OK, now what if I want to take another step so we cannot fail because we need to take her to tell. 70 00:05:30,270 --> 00:05:39,450 So the population automatically pops the I mean takes the top element and push prices in the to register. 71 00:05:41,460 --> 00:05:51,600 So now I want to say popi x so the top of it is seven and it's been placed into the X, the old memory 72 00:05:51,600 --> 00:05:54,760 or that off the X has been ordered at seven. 73 00:05:56,070 --> 00:06:00,600 Now as you can see before in the previous E.S.P points to this address. 74 00:06:00,870 --> 00:06:07,950 So whenever a pop operation has been executed, then E.S.P incremented by four. 75 00:06:08,250 --> 00:06:19,260 That means E.S.P no longer points to this seven because 05 is the top of the stack and E.S.P increments 76 00:06:19,260 --> 00:06:22,470 before when a popular pop operation has been performed. 77 00:06:23,220 --> 00:06:27,930 So what if I want to do the pop operation again? 78 00:06:28,740 --> 00:06:30,240 And now this. 79 00:06:30,720 --> 00:06:38,790 I want to say Popke X and the top of the stack before this pop is five and this fight will be copied 80 00:06:38,790 --> 00:06:39,690 in books. 81 00:06:40,740 --> 00:06:47,640 And then before E.S.P has been pointed to this eight four address and now after the Operation E.S.P 82 00:06:47,640 --> 00:06:54,300 point is pointing to the Aetate address, it means that Pusha Operation Decrements, the USP by four 83 00:06:54,300 --> 00:06:59,970 bytes and pop operation determines the value we increase the value for which. 84 00:07:03,070 --> 00:07:10,000 So as you can see, guys, when you are referring to the memory, actually you are the difference in 85 00:07:10,040 --> 00:07:12,160 these two memories addresses. 86 00:07:15,370 --> 00:07:23,260 So if you have taken my C programming course and you can see I have explained you in the studio and 87 00:07:23,290 --> 00:07:29,120 these two Artosis will be there on the stack and these values will also be on the stack. 88 00:07:29,800 --> 00:07:33,480 We are just not referencing this to memory Artosis and the. 89 00:07:35,400 --> 00:07:41,060 So Noguez will be moving on to the podium and let's do an example. 90 00:08:00,490 --> 00:08:05,800 That's no, I'm going to create a new car tag, but now some. 91 00:08:09,660 --> 00:08:12,690 Now, I'm going to write the global underscores. 92 00:08:16,670 --> 00:08:23,660 Now, I want to define a variable in the data section that I'm going to write the data section. 93 00:08:28,610 --> 00:08:31,310 Now, that's the variable, that one. 94 00:08:35,160 --> 00:08:36,180 Let's say over. 95 00:08:38,710 --> 00:08:45,690 Are we going to the world and we just put the of value onto the stock? 96 00:08:48,450 --> 00:08:53,980 So this word will point to that word and will be pushing this value onto the stack. 97 00:08:54,900 --> 00:08:58,620 Now let's create the U.S. to hold our core. 98 00:09:02,350 --> 00:09:06,790 And we need to define the start. 99 00:09:10,140 --> 00:09:16,160 OK, guys now will be moving some random values. 100 00:09:17,240 --> 00:09:31,320 Let's let's copy Google into the eggs and then let's push your eggs one zero three Litsa and we also 101 00:09:31,650 --> 00:09:33,810 push 066. 102 00:09:35,550 --> 00:09:46,950 But seven, now, these two values will be pushed onto the stack, now we can say bump into X. 103 00:09:49,640 --> 00:09:57,470 And this instruction will take the direct where you direct certain value and it in here, because it's 104 00:09:57,470 --> 00:10:02,390 the recent push and recent pop will take the risk and push value. 105 00:10:04,500 --> 00:10:07,490 I'm going to say pop Ebix. 106 00:10:09,330 --> 00:10:18,340 Now, this instruction will be the second pop operation from the last on what's the second push? 107 00:10:18,600 --> 00:10:24,980 I mean, Trevallyn will be presumably because know there is one more matter I want to show you. 108 00:10:25,710 --> 00:10:32,070 We can push particular bites of it, which I want to push forward. 109 00:10:35,470 --> 00:10:37,480 And said Brackett. 110 00:10:40,630 --> 00:10:41,230 Wear one. 111 00:10:41,560 --> 00:10:52,480 So what this what this means, push the content at one, but push only the word, I mean, push only 112 00:10:52,480 --> 00:11:01,090 the two bits of the content, look at it by the point or whatever one address knowledge of this. 113 00:11:03,020 --> 00:11:09,280 Let's talk about this in two weeks and also we will see. 114 00:11:12,510 --> 00:11:13,500 Bush Beever. 115 00:11:16,620 --> 00:11:24,540 There was the what is the four bites and we are going to push the four bites available one, and we 116 00:11:24,540 --> 00:11:31,440 will again pop this into evicts now we need to exit the program. 117 00:11:31,710 --> 00:11:32,340 To do that. 118 00:11:32,340 --> 00:11:35,730 We need to cover the right exit system called. 119 00:11:39,760 --> 00:11:47,470 Now pressing the one that is the number in two years and the exit of Girot, so we need to place the 120 00:11:47,770 --> 00:11:50,380 in and we need to call the interprete. 121 00:11:56,770 --> 00:11:58,150 So let me see the file. 122 00:12:00,700 --> 00:12:03,460 And we are going to compare it using that nasal. 123 00:12:14,290 --> 00:12:16,590 Now we will object to using Aldy. 124 00:12:30,320 --> 00:12:33,440 Now, our tag boundary has been created now later on this. 125 00:12:35,570 --> 00:12:40,140 So since we are not printing anything, the program just existed normally. 126 00:12:40,430 --> 00:12:44,760 Now let's open this binary in the bigger GDP, the bigger. 127 00:12:46,960 --> 00:12:48,640 Now, let's say in four functions. 128 00:12:53,190 --> 00:12:56,130 And I'm putting the breakpoint at the start function. 129 00:13:00,820 --> 00:13:10,040 Now, let me run the program now, as you can see, the next U.S. is going to be the movie zero two. 130 00:13:10,390 --> 00:13:14,280 So now let's run that introduction next time. 131 00:13:15,100 --> 00:13:18,470 So X condensed two and push three. 132 00:13:19,540 --> 00:13:21,650 So this is our guys. 133 00:13:21,790 --> 00:13:24,810 Now, there is already one and the address. 134 00:13:25,180 --> 00:13:31,240 So as you can see, this is the stack growing from here. 135 00:13:33,810 --> 00:13:37,660 That means if you place the element, it will be here. 136 00:13:39,130 --> 00:13:43,270 Now, let's run the step through the code. 137 00:13:44,080 --> 00:13:53,520 As you can see, three has been executed and the top of the stack contains three previous reads, one 138 00:13:53,590 --> 00:13:54,550 now it's three. 139 00:13:54,970 --> 00:13:59,230 As you can see, the address also has been created by four. 140 00:14:01,840 --> 00:14:10,090 As you can see now, the default Bush operation, sorry, push, Operation Default, KRI Decrements, 141 00:14:10,450 --> 00:14:17,380 yes, people thought it means that it takes the value and by default, it places the 32 bit where, 142 00:14:17,380 --> 00:14:23,020 you know, if I step through this again, you can see the direction. 143 00:14:24,040 --> 00:14:30,910 Now we are going to pop you now yak's contents to allow you to hand the top of the stack. 144 00:14:32,110 --> 00:14:37,180 So this initial action on execution, but this is the seven into the years. 145 00:14:38,890 --> 00:14:46,650 So no eggs content, seven in a similar manner directly is the top of the stack. 146 00:14:46,660 --> 00:14:50,680 And if you pop into buycks now, you can zero. 147 00:14:50,680 --> 00:14:52,060 It will be replaced by three. 148 00:14:53,710 --> 00:14:55,370 As you can see, Buycks contains three. 149 00:14:56,210 --> 00:14:59,800 Now we need to look something somewhat carefully. 150 00:14:59,800 --> 00:15:01,070 Push already. 151 00:15:01,120 --> 00:15:09,730 Well, in the previous pusher's, it default taken the B word that we do with and pushed down the stack. 152 00:15:10,210 --> 00:15:11,500 Now let's run this one. 153 00:15:11,680 --> 00:15:13,720 But only one operation. 154 00:15:21,870 --> 00:15:28,080 Now, as you can see now, let's take this to check the contents of this address. 155 00:15:43,730 --> 00:15:48,410 So the contents of this are 2046, OK? 156 00:15:48,980 --> 00:15:51,700 These should be placed onto the stack. 157 00:15:53,720 --> 00:15:55,130 I don't know why there is one. 158 00:15:55,730 --> 00:15:58,010 OK, now let's step through this. 159 00:16:04,910 --> 00:16:05,900 Now we are going to. 160 00:16:11,160 --> 00:16:19,110 Now we are going to push that the whole operation that we started to bits, actually, we have the 123456 161 00:16:19,110 --> 00:16:22,040 on it and that will be pushed under the stack. 162 00:16:22,500 --> 00:16:25,900 As you can see, there is Durex, 123456 on it. 163 00:16:26,850 --> 00:16:34,280 Now, if I pop into SBX this value and put it on, it will be comparable to this value this. 164 00:16:36,240 --> 00:16:39,630 Now, as you can see, it contains 123456 on it. 165 00:16:41,510 --> 00:16:49,400 Now, these last instructions tell us that we are calling that exercise stronger now, if I simply run 166 00:16:49,400 --> 00:16:59,810 this our program at just normal, guess one main thing you need to understand is the other portion of 167 00:16:59,810 --> 00:17:08,480 operations and the Bush operation decriminalizes people for bits and pop operation increments that. 168 00:17:08,480 --> 00:17:08,750 Yes. 169 00:17:08,870 --> 00:17:09,560 Wait for.