1 00:00:00,470 --> 00:00:06,590 Hello, my name is Stephan, and in this lecture we are going to create our Mac file, compile assembly 2 00:00:06,590 --> 00:00:08,990 and run our program. 3 00:00:08,990 --> 00:00:12,770 So here in previous lecture we just have this errors here. 4 00:00:12,770 --> 00:00:15,290 So I fix this and change this. 5 00:00:15,950 --> 00:00:19,630 We had the move here accidentally, right? 6 00:00:19,640 --> 00:00:25,280 It move as an instruction, but here you need to change it to pop. 7 00:00:25,280 --> 00:00:33,830 So this is the last final version of our code here and I will share this on the instructor on the lecture 8 00:00:33,830 --> 00:00:36,770 attachment sections, and that's it. 9 00:00:36,770 --> 00:00:40,040 So now we will clear the screen again. 10 00:00:40,040 --> 00:00:43,070 And as you can see, we have kikinda here. 11 00:00:43,070 --> 00:00:45,650 So we will create the gedit file. 12 00:00:45,650 --> 00:00:48,200 In this case we will go get it. 13 00:00:48,530 --> 00:00:55,370 Um, actually we can also use the mouse pad, text editor, mouse pad, the make file and that's it. 14 00:00:55,370 --> 00:00:57,200 So here, this is our mouse pad. 15 00:00:57,200 --> 00:01:03,290 So we will firstly add actually we can also add comments and so on. 16 00:01:05,270 --> 00:01:07,370 But however, now we will. 17 00:01:09,300 --> 00:01:09,570 Here. 18 00:01:09,570 --> 00:01:10,800 Let's kicking. 19 00:01:12,030 --> 00:01:13,140 Uh, actually, it's actually. 20 00:01:13,140 --> 00:01:16,170 It's far from the keyboard, so. 21 00:01:17,840 --> 00:01:21,110 So kicking here and we all. 22 00:01:22,330 --> 00:01:30,640 Bring that all here and GCC output file so you learn that what this means in previous lecture when we 23 00:01:30,670 --> 00:01:32,440 compile the Hello world application. 24 00:01:32,440 --> 00:01:35,680 So I will not this entailed in this lecture again. 25 00:01:36,770 --> 00:01:38,360 So kicking. 26 00:01:41,080 --> 00:01:42,910 Seeing that all here again. 27 00:01:42,910 --> 00:01:43,920 We will also. 28 00:01:44,670 --> 00:01:47,530 So, you know, pie. 29 00:01:47,920 --> 00:01:51,220 And after that, we'll go to the second line. 30 00:01:51,220 --> 00:01:55,810 So thinking that, oh, here, this is also. 31 00:01:56,840 --> 00:01:58,430 You're kicking that. 32 00:01:58,760 --> 00:02:00,080 We will take this file. 33 00:02:01,140 --> 00:02:11,010 Give it to Nasm f Elf 64 is going to be kicked or kicked over here and that's it. 34 00:02:11,010 --> 00:02:12,420 Save this make file here. 35 00:02:12,420 --> 00:02:18,060 And after that you can close this notepad here, close and make here. 36 00:02:18,060 --> 00:02:24,480 And as you can see here, our make file is created and our application is also compiled. 37 00:02:24,480 --> 00:02:28,950 So this make this typing make here. 38 00:02:28,950 --> 00:02:34,980 After creating your make file, it should compile and link your assembly code and. 39 00:02:37,000 --> 00:02:37,680 Here. 40 00:02:37,690 --> 00:02:40,360 You need to also keep in mind that. 41 00:02:42,640 --> 00:02:43,420 Make file. 42 00:02:46,230 --> 00:02:51,270 So here, keep in mind that you don't use the spaces here. 43 00:02:51,390 --> 00:02:55,620 You need to use the tabs and that's it. 44 00:02:55,650 --> 00:02:56,400 After that. 45 00:02:58,310 --> 00:02:59,820 Mike, and as you can see. 46 00:03:01,260 --> 00:03:03,780 Is up to date and that's it here. 47 00:03:03,780 --> 00:03:10,980 Now, what we're going to do is we will start our program and analysis and we will start the analysis 48 00:03:10,980 --> 00:03:11,310 phase. 49 00:03:11,310 --> 00:03:15,600 So clear Now, let's start our kicking program. 50 00:03:15,600 --> 00:03:18,660 And as you can see, hello world and alive. 51 00:03:18,660 --> 00:03:28,920 So in our first program, hello ASM, we passed the length of message here message MSG 13 characters 52 00:03:29,130 --> 00:03:37,620 and in in this RDX in order to display the message and kicking that we use a nice feature to calculate 53 00:03:37,620 --> 00:03:41,760 the length of our variables as you can see here. 54 00:03:41,760 --> 00:03:48,780 So the message minus negative message one minus one part means this here. 55 00:03:48,780 --> 00:04:00,090 So take this memory location and here the dollar sign and subtract the memory location of message to. 56 00:04:01,630 --> 00:04:04,570 And the result is the length of message. 57 00:04:04,870 --> 00:04:10,000 So and this this is the same applies for this message one here. 58 00:04:10,000 --> 00:04:16,270 So take this memory location and subtract the memory location of message one. 59 00:04:16,270 --> 00:04:18,880 So the result is the length message one. 60 00:04:18,880 --> 00:04:28,480 So that length minus one here, this is the string terminating zero and it is stored in the constant 61 00:04:28,510 --> 00:04:32,340 message one length here and. 62 00:04:33,950 --> 00:04:40,760 And and note keep in mind that the use of function prologue and the function epilogue in the code so 63 00:04:40,760 --> 00:04:43,820 these are the needed for gdb to function correctly. 64 00:04:43,820 --> 00:04:52,310 As pointed out in the previous lecture, the prologue and epilogue code will be explained in later sections 65 00:04:52,310 --> 00:05:01,760 and let's do some memory digging with the GDB here again because we love that here and now we will gdb 66 00:05:02,480 --> 00:05:05,320 kicking here and that's it. 67 00:05:05,330 --> 00:05:11,300 So then at the gdb prompt you type this disassemble. 68 00:05:13,150 --> 00:05:15,300 Amble, Maine. 69 00:05:15,520 --> 00:05:16,660 And that's it. 70 00:05:16,690 --> 00:05:19,990 So here, this will show this output here. 71 00:05:24,110 --> 00:05:28,940 So on your computer, it seems that the variable message. 72 00:05:30,150 --> 00:05:37,260 One variable message, one sits at a location or somewhere on the byte and. 73 00:05:41,640 --> 00:05:41,790 Yeah. 74 00:05:41,790 --> 00:05:43,680 What are we going to do is, uh. 75 00:05:43,710 --> 00:05:46,680 We will firstly check that, um. 76 00:05:52,950 --> 00:05:54,180 X as. 77 00:05:54,980 --> 00:05:56,780 Zero x. 78 00:05:58,620 --> 00:05:59,760 The one here. 79 00:05:59,910 --> 00:06:04,350 And as you can see, you can access to at the address. 80 00:06:04,560 --> 00:06:08,130 So what we're going to do is we will. 81 00:06:13,450 --> 00:06:19,350 Now, we will also try that with the message one with this and. 82 00:06:21,270 --> 00:06:21,900 One here. 83 00:06:21,900 --> 00:06:24,510 And as you can see, here is Hello World. 84 00:06:24,510 --> 00:06:26,820 And let's actually try the message tool. 85 00:06:26,820 --> 00:06:28,340 And this is the kicking and alive. 86 00:06:28,350 --> 00:06:35,760 So we got this memory addresses of message one and message two here and we can also find the numeric 87 00:06:35,760 --> 00:06:36,840 values here. 88 00:06:36,840 --> 00:06:46,590 So in order to find that, we will again use x, d, W, so we will reduce it, reduce, reduce. 89 00:06:46,590 --> 00:06:52,230 And here, as you can see, we got 357 and this is the radius. 90 00:06:52,230 --> 00:06:56,820 And now we get the get this P here. 91 00:06:57,210 --> 00:07:02,130 So radius and P, as you can see here, P is. 92 00:07:02,940 --> 00:07:04,800 7113. 93 00:07:11,410 --> 00:07:12,100 And that's it. 94 00:07:12,100 --> 00:07:13,860 So we got this here. 95 00:07:13,870 --> 00:07:16,330 As you can see, it's the floating point number. 96 00:07:16,990 --> 00:07:18,370 And that's why. 97 00:07:19,960 --> 00:07:29,230 Uh, we got a strange output here, and in order to fix that, we will, instead of using x here. 98 00:07:29,350 --> 00:07:30,550 X w here. 99 00:07:30,550 --> 00:07:38,650 So we got we can get this decimal and hexadecimal right value stored at the memory locations like radius 100 00:07:38,650 --> 00:07:39,790 and so on. 101 00:07:39,970 --> 00:07:47,740 And then we get a strange result when we try to get this floating point variable and print it on screen. 102 00:07:47,980 --> 00:07:55,570 And in order to do that we will just we will not use D or W, we will use F, g. 103 00:07:56,820 --> 00:08:00,990 And here after that, we will pass and that's it. 104 00:08:01,170 --> 00:08:04,740 So this is the shows up and we can also. 105 00:08:07,580 --> 00:08:10,220 And rally with X here and. 106 00:08:15,140 --> 00:08:16,700 P and that's it. 107 00:08:16,710 --> 00:08:19,660 And this is our the size of the variable. 108 00:08:19,670 --> 00:08:23,210 And now what we're going to do is we will. 109 00:08:26,130 --> 00:08:26,550 Slim. 110 00:08:27,180 --> 00:08:32,100 Actually, there's a subtlety that you should be aware of here. 111 00:08:32,100 --> 00:08:36,660 So to demonstrate, we will open the. 112 00:08:39,420 --> 00:08:40,680 We will open this. 113 00:08:43,910 --> 00:08:49,190 We actually created the LST using the Makefile. 114 00:08:49,460 --> 00:08:51,340 Let's actually do that again. 115 00:08:51,350 --> 00:08:57,290 So it's a pretty simple just open Makefile again. 116 00:09:04,370 --> 00:09:04,970 Emily. 117 00:09:07,750 --> 00:09:08,410 Project. 118 00:09:09,070 --> 00:09:14,320 As however mousepad eg file. 119 00:09:14,320 --> 00:09:19,050 So now you will learn how to create this l. 120 00:09:22,170 --> 00:09:23,130 While here. 121 00:09:26,190 --> 00:09:31,290 In order to do that, we will just add just a slight bit modification here. 122 00:09:31,440 --> 00:09:32,190 So. 123 00:09:33,070 --> 00:09:37,600 In the kicking that whole section here after this line that. 124 00:09:39,580 --> 00:09:39,980 Right. 125 00:09:40,280 --> 00:09:41,600 We will add. 126 00:09:42,640 --> 00:09:43,200 L. 127 00:09:44,040 --> 00:09:45,180 Uh, kicking. 128 00:09:45,800 --> 00:09:52,640 At least so because we need this so much here for analyzing. 129 00:09:55,580 --> 00:09:55,760 But. 130 00:09:57,120 --> 00:09:57,360 The. 131 00:10:00,810 --> 00:10:03,120 Begin Project Make here. 132 00:10:03,590 --> 00:10:07,970 And make it up to date as our place. 133 00:10:25,750 --> 00:10:26,110 Us. 134 00:10:26,810 --> 00:10:32,240 And as you can see, we got this kicking that this test here. 135 00:10:32,240 --> 00:10:34,370 So we wanted that, but it's okay. 136 00:10:34,700 --> 00:10:40,640 There's a, uh, actually this file extensions didn't make much difference in programming, low level, 137 00:10:40,970 --> 00:10:42,440 high level programming here. 138 00:10:42,440 --> 00:10:44,840 And that's why let's actually. 139 00:10:45,050 --> 00:10:46,520 Let's make it right. 140 00:10:46,520 --> 00:10:47,000 Right. 141 00:10:47,000 --> 00:10:53,200 So our, um, kicking or I'm kicking that LSTs and ram. 142 00:10:55,010 --> 00:10:57,950 Or I'm kicking that all here as. 143 00:11:00,790 --> 00:11:03,110 And I'll use the Mac. 144 00:11:04,030 --> 00:11:09,060 And as you can see, we have this LST file right here. 145 00:11:09,070 --> 00:11:18,790 So what we're going to do is we will firstly open this file with mouse pad again, the picking dot lst 146 00:11:19,180 --> 00:11:20,260 and that's it. 147 00:11:20,470 --> 00:11:23,020 So what we have here, there's a. 148 00:11:24,700 --> 00:11:28,030 Uh, so what we have here, we have the. 149 00:11:28,860 --> 00:11:31,620 Sections and the memories here. 150 00:11:32,250 --> 00:11:33,030 So. 151 00:11:34,070 --> 00:11:36,830 Now, you need to check this lines. 152 00:11:36,920 --> 00:11:39,650 Line ten and 11 here. 153 00:11:40,530 --> 00:11:43,380 And you'll also need to check. 154 00:11:44,280 --> 00:11:44,730 Yes. 155 00:11:44,850 --> 00:11:48,240 Line on 11 and here. 156 00:11:49,290 --> 00:12:00,130 On the left here, you can find the hexadecimal representation of the radius P And as you can see here. 157 00:12:01,440 --> 00:12:02,850 And instead of. 158 00:12:05,170 --> 00:12:07,120 0165. 159 00:12:07,150 --> 00:12:09,300 You find 62501. 160 00:12:09,310 --> 00:12:17,320 And instead of this which we got here, the hexadecimal number we got here. 161 00:12:17,740 --> 00:12:18,580 Remember that? 162 00:12:19,120 --> 00:12:20,650 Add it somewhere. 163 00:12:21,570 --> 00:12:22,260 Here. 164 00:12:28,020 --> 00:12:28,400 Excellent. 165 00:12:28,620 --> 00:12:29,340 Let's actually. 166 00:12:29,960 --> 00:12:30,470 As. 167 00:12:31,560 --> 00:12:32,640 And that makes. 168 00:12:33,870 --> 00:12:34,350 Again. 169 00:12:36,190 --> 00:12:38,170 Players gdb. 170 00:12:45,240 --> 00:12:52,890 So here we will again get that value for you so you can see what's the difference and where is the problem 171 00:12:53,100 --> 00:12:53,810 with that. 172 00:12:53,820 --> 00:12:58,990 So in order to do that we will just go for example XD. 173 00:13:00,330 --> 00:13:05,860 Actually let's get first a string and write that down here. 174 00:13:05,880 --> 00:13:10,800 Have string message one string message. 175 00:13:13,800 --> 00:13:22,830 But we first need this radius and pi here so we know that the value of radius, we obviously can see 176 00:13:22,830 --> 00:13:23,700 it here. 177 00:13:24,480 --> 00:13:24,660 Uh. 178 00:13:24,660 --> 00:13:27,480 King taking that He. 179 00:13:29,400 --> 00:13:31,070 Open a mousepad. 180 00:13:31,230 --> 00:13:34,740 So here we see this variables and values. 181 00:13:34,740 --> 00:13:37,800 But there's a strange here, so there's something wrong, actually. 182 00:13:38,580 --> 00:13:39,930 Our program will work, but. 183 00:13:41,100 --> 00:13:44,290 It has some warnings here, which we. 184 00:13:45,780 --> 00:13:48,620 You need to learn, uh, what what stands for. 185 00:13:48,630 --> 00:13:50,190 So I need to explain to you. 186 00:13:50,340 --> 00:13:51,330 Explain it to you. 187 00:13:51,330 --> 00:13:53,880 And now the W here. 188 00:13:54,000 --> 00:13:55,770 We will firstly get the radius. 189 00:13:55,770 --> 00:14:01,020 So, uh, with, with the W we get the radius value here. 190 00:14:01,020 --> 00:14:03,480 In this case, let's actually reduce. 191 00:14:03,480 --> 00:14:04,440 But we don't need that. 192 00:14:04,440 --> 00:14:06,030 We already can see it. 193 00:14:06,060 --> 00:14:13,530 We will use x, w and again we will also use f x here for the P. 194 00:14:16,420 --> 00:14:17,350 As the P here. 195 00:14:17,380 --> 00:14:18,160 That's it. 196 00:14:24,390 --> 00:14:26,080 X 50. 197 00:14:44,080 --> 00:14:45,790 Uh, yeah, that's it. 198 00:14:46,270 --> 00:14:46,960 So. 199 00:14:48,070 --> 00:14:49,750 As I said, instead of. 200 00:14:50,750 --> 00:14:51,230 This. 201 00:14:53,940 --> 00:14:56,130 0165. 202 00:14:57,060 --> 00:15:00,020 You're seeing 6501. 203 00:15:00,030 --> 00:15:04,320 So this is the bytes. 204 00:15:04,320 --> 00:15:10,050 The one byte in two hex numbers are in reverse order. 205 00:15:10,050 --> 00:15:13,680 So this characteristics is called indianness. 206 00:15:13,680 --> 00:15:19,830 So the big Indian format stores numbers the way we are used to seeing them. 207 00:15:19,830 --> 00:15:26,430 So with the most significant digits starting at the left and the left, Indian format stores the least 208 00:15:26,430 --> 00:15:29,570 significant numbers starting at the left. 209 00:15:29,580 --> 00:15:37,740 So Intel processors use little endian and that can be very confusing when looking at the hexadecimal 210 00:15:37,740 --> 00:15:38,010 code. 211 00:15:38,010 --> 00:15:44,040 So why do they have such strange names like Big in Indian and Little in Indian? 212 00:15:44,040 --> 00:15:50,820 So in 1726, Jonathan Swift wrote a famous novel. 213 00:15:51,150 --> 00:15:55,890 Villiers travels in the novel appear to fictional islands. 214 00:15:55,890 --> 00:16:03,940 So Lilliput and Blefuscu inhabitants of Lilliput are at war with the people of Blefuscu. 215 00:16:03,940 --> 00:16:08,830 But after break, eggs on the small island or on the bigger end. 216 00:16:08,860 --> 00:16:11,410 So little boats are little Indians. 217 00:16:11,410 --> 00:16:12,160 Indians. 218 00:16:12,160 --> 00:16:21,460 So preferring to break their eggs on the smaller ones and Basophils are big Indians, not Indians. 219 00:16:21,640 --> 00:16:22,540 Indians. 220 00:16:22,600 --> 00:16:28,480 Now you see that the modern computing has traditions rooted in the distant past. 221 00:16:28,480 --> 00:16:31,780 So take the time to single step through the program. 222 00:16:31,810 --> 00:16:34,450 Break main run Next, next, next. 223 00:16:34,450 --> 00:16:40,540 And you can see that GDB steps over the function block and edit the source code. 224 00:16:40,540 --> 00:16:45,880 Delete the function prologue epilogue and we make the program single step again with a gdb. 225 00:16:45,910 --> 00:16:50,580 In our case, gdb does not does refuse to single step at. 226 00:16:52,130 --> 00:16:52,910 The program. 227 00:16:52,910 --> 00:17:00,140 And when assembling with another assembler based on NSM, we can safely omit the prologue and epilogue 228 00:17:00,140 --> 00:17:02,750 code and step through the code with GDB. 229 00:17:02,900 --> 00:17:05,510 And sometimes it's necessary to experiment. 230 00:17:05,570 --> 00:17:07,880 Tinker and giggle around.