1 00:00:00,500 --> 00:00:06,950 Hello, my name is Typhoon and in this lecture we are going to write our Makefile to compile this program. 2 00:00:06,950 --> 00:00:12,890 Also we will get again as we did in the previous lecture, we will get the move that or output move 3 00:00:12,890 --> 00:00:16,400 that lStm and move that um M as well. 4 00:00:16,400 --> 00:00:20,390 And I will also produce the move executable move file. 5 00:00:20,690 --> 00:00:25,930 Um, well, so here what we're going to do is we will first go to, um. 6 00:00:27,020 --> 00:00:28,430 Assembly here. 7 00:00:28,550 --> 00:00:30,650 We have the Move project here. 8 00:00:31,380 --> 00:00:32,430 Um, as you can see. 9 00:00:32,460 --> 00:00:35,250 Oops, move, uh, clear here. 10 00:00:35,250 --> 00:00:37,550 So we have moved that here. 11 00:00:37,560 --> 00:00:42,030 What we're going to do is we will open our some text editors in this case. 12 00:00:42,030 --> 00:00:45,240 We also cannot convert gedit or mousepad. 13 00:00:45,270 --> 00:00:53,550 Yes, it depends on is here and we will create something named make file and that's it here. 14 00:00:53,730 --> 00:01:00,990 So what we're going to do is we will need to, uh, right, right here with move, start writing with 15 00:01:00,990 --> 00:01:01,860 move here. 16 00:01:02,010 --> 00:01:06,750 We will first create a move that all this line defines a rule in the make file. 17 00:01:06,750 --> 00:01:11,310 It states that the target move depends on the file move.org. 18 00:01:11,340 --> 00:01:16,350 So this means that if move that all is modified or doesn't exist. 19 00:01:16,350 --> 00:01:22,170 Um, then the target moves rebuilt using this comment here. 20 00:01:22,170 --> 00:01:26,010 And also, uh, we will. 21 00:01:26,700 --> 00:01:29,910 At GCC or move. 22 00:01:30,650 --> 00:01:35,010 But also we will use the no pi here, which I will explain right now. 23 00:01:35,030 --> 00:01:44,440 So this this command is used to link the object file, move that or into the executable named move here. 24 00:01:45,170 --> 00:01:51,440 So it uses the GCC compiler and this all here specifies the output file name. 25 00:01:51,440 --> 00:01:59,450 And this no Pi is a linker option that disables position independent executable in this case pi generation. 26 00:01:59,450 --> 00:02:06,260 So Pi is a security feature that randomizes the address space of the executable, but it's being disabled 27 00:02:06,260 --> 00:02:08,360 here because we want to debug it. 28 00:02:08,540 --> 00:02:15,110 So here we will also add the move.org here. 29 00:02:15,500 --> 00:02:17,620 Now we will move that ESM. 30 00:02:19,480 --> 00:02:23,140 So this line defines the another rule in the make file. 31 00:02:23,910 --> 00:02:29,710 It indicates that the target moved at all depends on the file moved at RSM. 32 00:02:29,730 --> 00:02:38,040 So if we move that RSM is modified or doesn't exist, the target moved at all needs to be rebuilt using 33 00:02:38,040 --> 00:02:39,300 this command here. 34 00:02:39,300 --> 00:02:48,900 Nasm f elf 64 g Move that SM or move that all here and move that LST. 35 00:02:48,930 --> 00:02:56,970 So this command assembles the assembly file, move that RSM using the Nasm here Elf 64. 36 00:02:57,000 --> 00:03:00,540 Now let's break the down options and arguments here. 37 00:03:00,540 --> 00:03:06,960 So f Elf 64 specifies the output format to be Elf 64. 38 00:03:07,200 --> 00:03:14,820 The G here generates a debugging information which can be useful for debugging with tools like GDB or 39 00:03:15,390 --> 00:03:16,110 here. 40 00:03:16,110 --> 00:03:24,580 And this move that RSM this is a source assembly file to be assembled and not this all move that all 41 00:03:24,580 --> 00:03:29,710 here specifies the output file name as moveto and L here. 42 00:03:29,710 --> 00:03:35,470 This is the generates a listing file containing the assembly code along with the memory addresses so 43 00:03:35,470 --> 00:03:40,990 the this listing can be helpful for reviewing reviewing the assembly code as well. 44 00:03:40,990 --> 00:03:48,010 So to summarize the provide a set of commands and rules as are part of the make file which is used Automate 45 00:03:48,010 --> 00:03:50,620 the build process for an assembler program. 46 00:03:50,620 --> 00:03:57,190 So the make file defines how the executable move is built from the assembly source file and move that 47 00:03:57,220 --> 00:04:06,260 RSM by by assembling it into an object file, move that over here and then linking it to g C. 48 00:04:06,670 --> 00:04:13,210 So now what we're going to do is we will save this file right now here and we will continue. 49 00:04:14,110 --> 00:04:20,590 On drawing or on starting out and debugging or JC here. 50 00:04:20,680 --> 00:04:22,380 So now, uh, here. 51 00:04:22,390 --> 00:04:23,290 Clear. 52 00:04:23,410 --> 00:04:29,890 So, cat make file and as you can see, make file is written here and here. 53 00:04:29,890 --> 00:04:33,450 Now we will just press write make, and that's it. 54 00:04:33,460 --> 00:04:35,020 Our program is compiled. 55 00:04:35,020 --> 00:04:38,230 And as you can see, we have this executable file here. 56 00:04:38,230 --> 00:04:43,560 So if we run this and as you can see, we have no output because we are working in a memory. 57 00:04:43,570 --> 00:04:47,230 So now, uh, we saved, uh, the source file. 58 00:04:47,230 --> 00:04:48,850 Yes, everything is okay. 59 00:04:48,850 --> 00:04:53,330 And here we will need to start a triple D, so I will call it D. 60 00:04:54,800 --> 00:04:56,320 The DVD here. 61 00:04:56,690 --> 00:04:57,410 Move. 62 00:04:57,530 --> 00:04:58,700 And that's it. 63 00:04:59,210 --> 00:05:03,860 We installed DDT in actual dribbled is more easy to pronounce. 64 00:05:03,860 --> 00:05:05,070 So I use I. 65 00:05:05,090 --> 00:05:10,160 We installed a triple D in previous lectures, so we will not install it again. 66 00:05:10,910 --> 00:05:17,320 And here we have some informations on blah blah blah here and that's it. 67 00:05:17,330 --> 00:05:23,720 So here you will see this graphical user interface with a rather dated layout. 68 00:05:23,720 --> 00:05:30,590 And DDT is an old open source tool and apparently nobody is willing to adapt it to the graphical user 69 00:05:30,590 --> 00:05:32,780 interface standards we are used today. 70 00:05:32,780 --> 00:05:40,460 And so you have a window with your source file, source code displayed and window where you can type 71 00:05:40,880 --> 00:05:43,370 gdb, gdb command. 72 00:05:43,370 --> 00:05:48,560 So there is also a floating panel where you can click run here. 73 00:05:49,300 --> 00:05:50,510 And see, here we are. 74 00:05:50,530 --> 00:05:51,340 This is the terminal. 75 00:05:51,340 --> 00:05:59,440 We can type GDB commands and if we click on the service menu and um, let's actually click on the source, 76 00:05:59,440 --> 00:06:00,670 uh, menu and. 77 00:06:01,430 --> 00:06:01,940 Um. 78 00:06:03,940 --> 00:06:04,510 Here. 79 00:06:04,540 --> 00:06:06,820 Uh, as you can see here, uh, menu. 80 00:06:06,820 --> 00:06:08,350 And we can, uh, display. 81 00:06:08,710 --> 00:06:09,730 Display. 82 00:06:09,730 --> 00:06:11,320 Uh, line numbers. 83 00:06:15,390 --> 00:06:15,930 Here for. 84 00:06:16,020 --> 00:06:23,100 As you can see here, we have find find words only find case sensitive only line numbers, display machine 85 00:06:23,100 --> 00:06:24,600 code in the source and so on. 86 00:06:24,600 --> 00:06:27,000 So we will click on display line numbers. 87 00:06:27,090 --> 00:06:35,810 Um, we can see the line numbers on the left like the most the new text editors and in the same menu 88 00:06:35,820 --> 00:06:41,100 can choose have a window with the assembled code as well. 89 00:06:41,100 --> 00:06:49,440 So now, uh, we will place the cursor here on this, uh, main and we will right click here. 90 00:06:50,630 --> 00:06:56,840 And here, as you can see here, we will actually let's actually place run here. 91 00:06:57,800 --> 00:07:01,460 And here we can in right click on it. 92 00:07:02,480 --> 00:07:03,530 Now, uh, here. 93 00:07:03,530 --> 00:07:06,590 We can also set the breakpoint here. 94 00:07:12,940 --> 00:07:24,790 Also we now we if we run this again and this, you can see we're one breakpoint main at that in 15 line. 95 00:07:25,980 --> 00:07:26,790 And. 96 00:07:28,290 --> 00:07:29,220 Here. 97 00:07:29,610 --> 00:07:32,250 Uh, let's actually right click on the again. 98 00:07:33,030 --> 00:07:36,090 And as you can see, we have also commands program. 99 00:07:37,800 --> 00:07:38,640 Cool here. 100 00:07:38,640 --> 00:07:40,410 Edit on. 101 00:07:50,210 --> 00:07:54,590 And here again, delete this breakpoint. 102 00:07:55,560 --> 00:07:56,190 Sable. 103 00:07:56,190 --> 00:07:58,470 You can also delete and disable the breakpoints. 104 00:07:58,470 --> 00:08:01,710 But here in this case, let's actually delete again and I will. 105 00:08:01,830 --> 00:08:03,120 Let's run it again. 106 00:08:03,120 --> 00:08:10,800 So what we're going to see is and what we are need to see is we will need to see registers, which this 107 00:08:10,800 --> 00:08:12,930 is the whole logic of this code. 108 00:08:12,930 --> 00:08:19,620 That's why we written this code to show something on registers, uh, which now we will add the main, 109 00:08:19,620 --> 00:08:22,530 uh, main the breakpoint at the main here. 110 00:08:23,290 --> 00:08:32,170 And to observe and understand how the content of registers changes with the this move command, we will 111 00:08:32,170 --> 00:08:32,810 follow. 112 00:08:33,200 --> 00:08:40,900 We need to place the cursor in the front of the main here and we right click on it. 113 00:08:43,300 --> 00:08:46,060 And now we will choose a break. 114 00:08:47,080 --> 00:08:49,790 Or you can also click the. 115 00:08:49,840 --> 00:08:52,780 Yes, uh, you can also click break here on. 116 00:08:53,630 --> 00:08:54,440 It's on break. 117 00:08:55,320 --> 00:08:56,040 And. 118 00:08:57,310 --> 00:09:04,840 Or you can also click on the top of this menu, uh, on the, uh, stop icon here, as you can see here. 119 00:09:06,710 --> 00:09:07,850 But it's right. 120 00:09:07,970 --> 00:09:09,770 Just right click on it and choose break. 121 00:09:09,770 --> 00:09:16,220 And then we will click on Run here on the floating panel debugging. 122 00:09:16,250 --> 00:09:18,620 So this will start a debugging process. 123 00:09:18,620 --> 00:09:25,400 And now we will click on the status here in the top menu bar and then select registers. 124 00:09:25,400 --> 00:09:31,370 So this action will open a window displaying the current values of registers here. 125 00:09:32,830 --> 00:09:33,290 Here. 126 00:09:38,310 --> 00:09:39,120 Make it a little. 127 00:09:43,150 --> 00:09:43,630 But will. 128 00:09:44,520 --> 00:09:45,280 To our screens. 129 00:09:45,290 --> 00:09:47,090 Oh, this is so wide here. 130 00:09:47,470 --> 00:09:47,850 Don't need. 131 00:09:53,140 --> 00:09:55,720 This debugger needs to be updated at. 132 00:09:56,500 --> 00:09:57,760 Graphical here. 133 00:09:57,850 --> 00:09:58,930 But this. 134 00:10:23,590 --> 00:10:25,590 And that's it here. 135 00:10:25,600 --> 00:10:26,410 So. 136 00:10:27,820 --> 00:10:36,640 And after that we will click on this step here to execute the current instruction in the program. 137 00:10:41,130 --> 00:10:41,580 This. 138 00:10:48,600 --> 00:10:49,620 And see here. 139 00:10:50,420 --> 00:10:51,260 Up in. 140 00:10:54,770 --> 00:10:56,060 And here. 141 00:10:57,970 --> 00:11:01,090 As you click this step, you will observe. 142 00:11:01,210 --> 00:11:07,300 You will able to observe how the values in registers change with each step through the program. 143 00:11:07,570 --> 00:11:17,050 If you wish to inspect memory addresses like you num1 or be num, uh, you can uh, go to the view option 144 00:11:17,050 --> 00:11:17,710 here. 145 00:11:18,570 --> 00:11:23,580 And to make the data window visible here and under this data. 146 00:11:26,630 --> 00:11:27,320 But now it's. 147 00:11:28,980 --> 00:11:29,160 I'll. 148 00:11:30,810 --> 00:11:31,230 Was this. 149 00:11:31,230 --> 00:11:32,310 No, we don't want to close this. 150 00:11:32,310 --> 00:11:35,460 I don't want to do it again from zero here. 151 00:11:35,460 --> 00:11:36,600 Let's actually make it. 152 00:11:38,280 --> 00:11:39,000 Down here. 153 00:11:39,690 --> 00:11:41,550 And here, um. 154 00:11:42,000 --> 00:11:45,000 Under here and go from here. 155 00:11:45,750 --> 00:11:46,010 Step. 156 00:11:48,460 --> 00:11:49,030 Here. 157 00:11:49,840 --> 00:11:51,850 Up and up. 158 00:11:52,360 --> 00:11:53,080 Finish. 159 00:11:54,480 --> 00:11:55,260 Interrupt. 160 00:11:56,360 --> 00:11:56,730 That's it. 161 00:11:56,750 --> 00:11:58,190 Now we will run it again. 162 00:12:01,730 --> 00:12:02,900 And here. 163 00:12:06,330 --> 00:12:06,690 You. 164 00:12:07,740 --> 00:12:08,610 Data window. 165 00:12:12,230 --> 00:12:12,680 Even though. 166 00:12:21,440 --> 00:12:24,560 And here, as you can see here, we are seeing our variables as well. 167 00:12:25,230 --> 00:12:28,380 But the most important thing here is in registers. 168 00:12:28,500 --> 00:12:30,540 So and keep in mind that. 169 00:12:31,610 --> 00:12:32,270 Here. 170 00:12:32,880 --> 00:12:39,060 Keep in mind that the while DVD has a graphical interface, it can sometimes be intricate to navigate. 171 00:12:39,060 --> 00:12:44,140 So if you find it faster you can use gdb which is uh, this. 172 00:12:44,220 --> 00:12:52,290 GDB is better, which is and gdb input window for better for certain tasks. 173 00:12:52,290 --> 00:12:58,020 And it's important to keep in mind that DVD is built up on top of gdb. 174 00:12:58,440 --> 00:13:04,710 The new debugger and consequently using a proper function, prologue and epilogue code is essential 175 00:13:04,710 --> 00:13:11,520 to avoid potential uses during the program execution and typically ignores the function prologue while 176 00:13:11,520 --> 00:13:14,820 stepping with the code here. 177 00:13:14,970 --> 00:13:21,840 And the primary objective of this code is to demonstrate how the move command actually again I want 178 00:13:21,840 --> 00:13:25,950 to do it again here how this move command. 179 00:13:28,380 --> 00:13:32,220 Here impacts the contents of registers. 180 00:13:32,220 --> 00:13:32,850 Right. 181 00:13:33,770 --> 00:13:35,210 As you can see, in racks. 182 00:13:35,960 --> 00:13:38,420 You're always changing the here. 183 00:13:40,410 --> 00:13:41,150 Now see here. 184 00:13:41,160 --> 00:13:44,340 Now it's one, two, three, four, five, six. 185 00:13:45,100 --> 00:13:45,520 An. 186 00:13:46,640 --> 00:13:48,220 It's done because there's a. 187 00:13:50,020 --> 00:13:52,810 Its program is at the read here. 188 00:13:52,810 --> 00:13:55,830 So interrupt it, run it again. 189 00:13:55,840 --> 00:14:00,580 And as you can see, Rex is something just random thing here. 190 00:14:00,970 --> 00:14:06,190 But and in this here we are filling Rex with once. 191 00:14:07,270 --> 00:14:10,510 And here we are. 192 00:14:10,510 --> 00:14:11,110 Step. 193 00:14:13,050 --> 00:14:13,530 Here. 194 00:14:13,830 --> 00:14:20,220 And as you can see here, here now, Rex has the correct value here, which is zero for now. 195 00:14:20,220 --> 00:14:22,650 And here we are filling Rex with ones. 196 00:14:22,650 --> 00:14:30,720 And as you can see, here is the Rex value is one, two, three step again minus one as it did here. 197 00:14:30,930 --> 00:14:37,110 Then again, minus five, 319, one step again and zero again. 198 00:14:37,110 --> 00:14:43,530 So now let's step again and one, two, three, four, five, six, which is the value of our. 199 00:14:44,470 --> 00:14:45,880 Welcome here. 200 00:14:48,010 --> 00:14:48,670 One, two. 201 00:14:49,610 --> 00:14:49,830 We? 202 00:14:49,910 --> 00:14:50,330 Yes. 203 00:14:53,160 --> 00:14:54,090 Again, minus one. 204 00:14:54,090 --> 00:14:56,340 And here we also. 205 00:14:59,390 --> 00:15:00,050 Again. 206 00:15:01,130 --> 00:15:03,230 And no one here. 207 00:15:04,320 --> 00:15:05,430 And after that. 208 00:15:06,750 --> 00:15:13,590 Lastly, we are seeing this move Racks Keenum 123456 here. 209 00:15:14,200 --> 00:15:18,280 And here we are, instruction for floating point number. 210 00:15:20,060 --> 00:15:21,740 And that's it. 211 00:15:23,670 --> 00:15:30,720 So this is, um, how have you, as you continue stepping through the code, you will notice that when 212 00:15:30,720 --> 00:15:38,650 you move a 32 bit value into a 64 bit, register the higher bits in the 64 bit registers are cleared. 213 00:15:38,670 --> 00:15:45,300 So likewise, when you move value in to ax the upper bits of Rax are cleared. 214 00:15:45,390 --> 00:15:51,870 Well, so this insight is vital to keep in mind during programming and debugging.