1 00:00:00,610 --> 00:00:01,450 Hello, my name is Steve. 2 00:00:01,630 --> 00:00:02,560 Welcome to this lecture. 3 00:00:02,560 --> 00:00:06,940 And in this lecture we are going to compile this program, create a mac file for it. 4 00:00:06,940 --> 00:00:10,850 And also I will explain this code line by line first. 5 00:00:10,900 --> 00:00:15,310 First of all, let's actually make our code look nicer here. 6 00:00:15,310 --> 00:00:18,970 Let's add a enter here, the new line. 7 00:00:19,970 --> 00:00:22,120 Have a new line. 8 00:00:22,120 --> 00:00:22,960 And also. 9 00:00:24,290 --> 00:00:25,280 New line here. 10 00:00:25,280 --> 00:00:28,880 So the code is going to be read for us. 11 00:00:29,810 --> 00:00:30,710 And that's it. 12 00:00:30,890 --> 00:00:36,620 So now here, let's get started by explaining this code by line by line. 13 00:00:36,860 --> 00:00:44,390 And what we're going to do is firstly, I will explain this data section, which are which we are defining 14 00:00:44,420 --> 00:00:47,560 the various data variables with different sizes. 15 00:00:47,570 --> 00:00:50,600 So actually we also need the grommet. 16 00:00:50,720 --> 00:00:53,510 Let's actually mark it down to. 17 00:00:57,660 --> 00:01:00,540 Now we are I'm explaining this data here. 18 00:01:00,540 --> 00:01:07,770 So in the first year in Vietnam, we are defining a bite size. 19 00:01:07,770 --> 00:01:12,390 In this case, eight bits for this exploit. 20 00:01:13,920 --> 00:01:17,100 Okay, So this is eight bits. 21 00:01:17,940 --> 00:01:21,750 Um, variable with the value of one, two, three. 22 00:01:21,750 --> 00:01:23,490 And in w num. 23 00:01:23,490 --> 00:01:30,960 Here we are defining a word size in this case, 16 bits. 24 00:01:32,010 --> 00:01:37,100 Um, 16 bits variable with the value of one, two, three, four, five. 25 00:01:37,110 --> 00:01:42,450 And in the Num we are defining a double word size. 26 00:01:42,450 --> 00:01:52,530 In this case it is 32 bits, a variable with a value of 1234567890. 27 00:01:52,530 --> 00:02:02,280 And in num one we are defining a quad word size variable with the value of this here. 28 00:02:02,280 --> 00:02:10,170 In this case, this variable size is 64 bits here, 64 bits. 29 00:02:10,590 --> 00:02:15,360 In this case it's 32 bits, 16 bits and eight bits. 30 00:02:15,570 --> 00:02:21,570 And also in num one, yes, we are defining the 64 bits we already explained. 31 00:02:21,570 --> 00:02:31,660 And in M2 we are defining another quad word size variable with the value of one, two, three, four, 32 00:02:31,660 --> 00:02:32,440 five, six. 33 00:02:32,440 --> 00:02:43,180 In this case, this is also 64 bit and also this is also 64 bit because we defined that as a quad word 34 00:02:43,180 --> 00:02:44,590 size variable. 35 00:02:44,590 --> 00:02:52,480 So and in N3 we are again defining a codeword size variable with the value of 3.14. 36 00:02:52,690 --> 00:02:56,020 It is also 64 bits here. 37 00:02:57,280 --> 00:03:05,350 And here in the section, the section will normally contain initialized data, uninitialized data. 38 00:03:05,350 --> 00:03:09,000 But it seems like there's a we didn't add. 39 00:03:09,250 --> 00:03:18,400 No variables are defined in the section because we don't have any unusual uninitialized data here and 40 00:03:18,490 --> 00:03:20,380 here in this section. 41 00:03:20,380 --> 00:03:29,440 We as you can see, yes, in the section text here, this is the section is for code instruction. 42 00:03:29,440 --> 00:03:37,660 This global main directive specifies that the symbol main is globally accessible entry point for the 43 00:03:37,660 --> 00:03:38,500 program. 44 00:03:38,500 --> 00:03:45,880 And also we have this main push rb r, BP and RWP rsp. 45 00:03:46,240 --> 00:03:51,130 This is this main label marks the start of the main function. 46 00:03:51,490 --> 00:03:58,250 So this code sets up a basic function prologue by saving saving the current value of the base pointer 47 00:03:58,280 --> 00:04:07,640 r bp onto the stack and then copying the current stack pointer rsp into our BP here. 48 00:04:08,210 --> 00:04:13,720 So and after that, we have four lines of code defined here. 49 00:04:13,730 --> 00:04:22,780 So this is for the these are the instructions, um, manip to manipulate the rax register. 50 00:04:22,790 --> 00:04:26,870 This is a general purpose 64 bit register. 51 00:04:26,870 --> 00:04:29,750 So rax is 64 bit. 52 00:04:29,750 --> 00:04:37,640 But you can also open this cheat sheet cheat sheet for the 64 bit registers here. 53 00:04:37,640 --> 00:04:40,880 So 64 bit registers. 54 00:04:40,880 --> 00:04:51,170 So here, as I added comments here, the move rax minus one fills the entire rax register with ones. 55 00:04:51,530 --> 00:04:58,100 This move a l bite b num loads the value of b num. 56 00:04:58,100 --> 00:05:05,540 In this case b is 123 into the lower eight bits of rax preserving the upper bits. 57 00:05:05,540 --> 00:05:09,680 And also we have the XOR rax rax. 58 00:05:09,680 --> 00:05:17,590 This clears all bits, all bits in rax and move a l bite b num. 59 00:05:17,600 --> 00:05:23,660 Again, we are using one, two, three calls, we are using B now which holds the value of 123. 60 00:05:23,690 --> 00:05:32,270 This loads the value of b num into the lower eight bits of rax now correctly here, so similar instructions 61 00:05:32,270 --> 00:05:35,300 are used for this. 62 00:05:39,020 --> 00:05:39,520 Here. 63 00:05:39,560 --> 00:05:51,920 A similar instructions are used for here, a x and a word here, a keyword and a x, which is, as you 64 00:05:51,920 --> 00:05:53,410 can see, for Vina. 65 00:05:54,650 --> 00:06:01,520 And so we are again manipulating this rax register here. 66 00:06:01,700 --> 00:06:07,970 So move rax minus one again fills the rax with once more rax keyword w num. 67 00:06:09,170 --> 00:06:13,090 Loads the value of uh, the PR uh. 68 00:06:14,260 --> 00:06:16,000 W I'm here again. 69 00:06:16,000 --> 00:06:22,090 But this is the almost the same with this one here in the previous one. 70 00:06:22,090 --> 00:06:25,240 But what's interesting here is this. 71 00:06:25,420 --> 00:06:28,920 So again, we are at the start. 72 00:06:28,930 --> 00:06:30,520 We are all the same. 73 00:06:30,520 --> 00:06:39,820 So we are moving the racks, move racks minus one is fills the entire racks register with once again. 74 00:06:39,820 --> 00:06:42,760 You can also use this to learn this registers. 75 00:06:42,760 --> 00:06:46,300 You can also open the Nasm cheat sheet. 76 00:06:47,410 --> 00:06:50,680 You can find that in anywhere. 77 00:06:50,890 --> 00:06:54,940 So you can use that to learn about these registers as well. 78 00:06:54,940 --> 00:07:01,000 So here after that we move racks Keyboard Keenan one. 79 00:07:01,120 --> 00:07:04,930 This loads the value of Keenan into racks. 80 00:07:05,260 --> 00:07:14,510 So we are in this here we are overwriting the previous value of racks and move keyword to Num2 racks. 81 00:07:14,510 --> 00:07:19,850 This stores the value of racks into enum to. 82 00:07:20,870 --> 00:07:24,680 And the lastly mov rax 123456. 83 00:07:24,710 --> 00:07:29,840 This loads the immediate value of 123456 in Rax. 84 00:07:29,840 --> 00:07:40,580 And lastly, what we have here actually we need to instead of using that we need to use mov s mov. 85 00:07:45,400 --> 00:07:46,390 Move here. 86 00:07:46,420 --> 00:07:47,080 So. 87 00:07:48,420 --> 00:07:48,930 Move. 88 00:07:51,300 --> 00:07:52,230 Or still here? 89 00:07:52,230 --> 00:07:52,800 Yes. 90 00:07:52,920 --> 00:07:53,280 This. 91 00:07:53,280 --> 00:07:56,280 This here needs to move here. 92 00:07:56,280 --> 00:07:56,910 So move. 93 00:07:56,940 --> 00:08:05,910 SD So this instruction loads double precision floating point number from the memory location key M3 94 00:08:05,910 --> 00:08:08,580 into Xmm0 register. 95 00:08:08,580 --> 00:08:15,240 And also keep in mind that must is a special instructions for handling floating point number because 96 00:08:15,240 --> 00:08:26,820 in Q and M3 we have the floating point number which is 3.14, and after that we just have several instructions. 97 00:08:27,210 --> 00:08:34,410 So this is here, these instructions here mov rsp rbp pop rbp here. 98 00:08:34,410 --> 00:08:40,470 So these instructions perform the function Epilogue Storing the stack pointer, rsp and base pointer 99 00:08:40,510 --> 00:08:43,410 are to their original values. 100 00:08:43,440 --> 00:08:47,220 This ret instructions is new to us here. 101 00:08:47,220 --> 00:08:49,410 This RET instruction is new to us. 102 00:08:49,440 --> 00:08:54,760 This instruction returns from the main function which we didn't actually use that. 103 00:08:55,730 --> 00:08:55,990 Lecture. 104 00:08:56,090 --> 00:08:58,730 So please also keep in mind that this code is. 105 00:08:59,610 --> 00:09:03,870 The x86 64 assembly language and syntax. 106 00:09:03,870 --> 00:09:11,580 While I explained individual lines, it's important to make sure that code is properly assembled and 107 00:09:11,580 --> 00:09:14,740 executed with a within a suitable environment. 108 00:09:14,760 --> 00:09:22,200 And now what we're going to do is we will first compile it with the make. 109 00:09:22,350 --> 00:09:29,160 We will create the make file in the next lecture and we will also use the triple dee dee dee dee debugger 110 00:09:29,160 --> 00:09:37,320 for debugging our application, which obviously this this will not provide any console output like printing 111 00:09:37,320 --> 00:09:46,680 the words Hello world, but it actually does operations in memory which we will uh, analyze that and 112 00:09:46,680 --> 00:09:48,270 debug that in next lecture. 113 00:09:48,270 --> 00:09:49,620 So I'm waiting you in next lecture.