1 00:00:00,320 --> 00:00:04,850 Hello, my name is Stephan, and in this lecture we will develop another assembly program. 2 00:00:04,850 --> 00:00:12,470 And now that you have a firm grasp of GDB and know what an assembly program looks like, let's add some 3 00:00:12,470 --> 00:00:13,430 complexity. 4 00:00:13,460 --> 00:00:18,920 In this lecture I will show you how to obtain the length of a string variable. 5 00:00:19,100 --> 00:00:26,300 I will show you how to print integer and floating point values using printf and I will expand your knowledge 6 00:00:26,300 --> 00:00:28,210 of GDB commands. 7 00:00:28,220 --> 00:00:36,530 So now here we will firstly open CSM or you can also choose another text editor so you don't need much 8 00:00:36,530 --> 00:00:39,410 about creating or developing assembly code. 9 00:00:39,620 --> 00:00:43,070 And let's actually use the CSM here. 10 00:00:43,070 --> 00:00:44,720 Now create a new project here. 11 00:00:44,720 --> 00:00:47,270 Let's delete this project, save it somewhere. 12 00:00:47,270 --> 00:00:51,170 In this case, let's actually our project name is going to be kicking. 13 00:00:52,340 --> 00:00:52,910 That's it. 14 00:00:52,940 --> 00:00:57,500 Now save it as the name of kicking that --. 15 00:00:57,950 --> 00:00:58,580 That's it. 16 00:00:58,580 --> 00:01:00,740 And here is our code. 17 00:01:00,770 --> 00:01:03,860 Now we will firstly comment it out. 18 00:01:03,860 --> 00:01:05,840 Our the. 19 00:01:07,350 --> 00:01:11,400 Assembly program, name, file name, RSM here. 20 00:01:11,430 --> 00:01:18,810 Now we will firstly add this data section in it here because we will add the two variables. 21 00:01:18,810 --> 00:01:21,510 It's actually two variables, but we will add four variables. 22 00:01:21,510 --> 00:01:27,270 The two variables is for the our string and string. 23 00:01:27,300 --> 00:01:33,810 And the second variables is the length of the first string and the length of the second string. 24 00:01:33,810 --> 00:01:43,260 Now here we will firstly write this the message MSG one db here. 25 00:01:43,650 --> 00:01:44,850 Hello world. 26 00:01:45,000 --> 00:01:48,270 Let's actually case sensitive words here. 27 00:01:48,390 --> 00:01:51,930 Hello world and ten zero. 28 00:01:52,900 --> 00:01:54,950 And a comma and zero here. 29 00:01:54,970 --> 00:01:56,560 So what? 30 00:01:56,800 --> 00:01:58,540 So this is something new, right? 31 00:01:58,540 --> 00:02:00,790 So we added zero for the null terminated. 32 00:02:01,240 --> 00:02:04,990 But here we added ten, which I will explain right now. 33 00:02:04,990 --> 00:02:10,390 So this is the string with an L and zero. 34 00:02:12,000 --> 00:02:15,060 The string width and zero here. 35 00:02:15,690 --> 00:02:17,340 We will also have the. 36 00:02:19,000 --> 00:02:20,240 Message one. 37 00:02:20,260 --> 00:02:21,670 Length here. 38 00:02:21,790 --> 00:02:23,170 Actually, length is okay. 39 00:02:23,170 --> 00:02:32,380 So we will write here and what we're going to do, we will take this message variable minus message 40 00:02:32,380 --> 00:02:33,670 one, minus one. 41 00:02:33,670 --> 00:02:38,770 So this is for measuring the length minus the zero here. 42 00:02:38,770 --> 00:02:40,450 So measure. 43 00:02:41,550 --> 00:02:43,320 Measure the length. 44 00:02:44,200 --> 00:02:49,240 Of message one and minus. 45 00:02:50,030 --> 00:02:54,560 The zero and we will also create our string two. 46 00:02:55,490 --> 00:02:58,400 We will name it MSG two. 47 00:02:58,460 --> 00:03:02,750 Here we will write it DB right here. 48 00:03:02,750 --> 00:03:09,530 And our message is going to be kicking and alive this here. 49 00:03:09,740 --> 00:03:10,610 So. 50 00:03:12,130 --> 00:03:12,430 Here. 51 00:03:12,430 --> 00:03:13,390 We will also. 52 00:03:15,270 --> 00:03:17,750 All this again, ten and zero. 53 00:03:17,750 --> 00:03:23,540 Remember, this ten is for new line and is for nation. 54 00:03:24,200 --> 00:03:26,920 So we will terminate our string after new line. 55 00:03:26,930 --> 00:03:27,280 Right. 56 00:03:27,320 --> 00:03:32,840 So string with L and zero here. 57 00:03:35,720 --> 00:03:39,680 And after that, we will also create the search tool. 58 00:03:39,680 --> 00:03:40,610 Len, here. 59 00:03:40,640 --> 00:03:43,610 This is going to be, again, equal here. 60 00:03:43,700 --> 00:03:48,590 And here we will again measure the length and we will miss the zero. 61 00:03:48,770 --> 00:03:51,740 So a message to. 62 00:03:52,710 --> 00:03:54,720 Minus one here. 63 00:03:55,740 --> 00:03:58,560 So this is for the measure. 64 00:03:59,450 --> 00:04:03,110 The length of message to. 65 00:04:04,980 --> 00:04:06,300 Plus minus. 66 00:04:08,070 --> 00:04:08,970 The zero. 67 00:04:10,260 --> 00:04:13,770 And here we will create some radius. 68 00:04:13,770 --> 00:04:15,510 So this is the radius. 69 00:04:15,510 --> 00:04:21,870 And pi is actually the terminology for you, which you will learn by the end of this section. 70 00:04:21,990 --> 00:04:25,990 I will explain this terminologies deeply later. 71 00:04:26,010 --> 00:04:27,540 So radius. 72 00:04:28,340 --> 00:04:31,790 Be cool not to be here and. 73 00:04:31,790 --> 00:04:34,550 357. 74 00:04:35,410 --> 00:04:37,300 And we will add comments. 75 00:04:37,300 --> 00:04:41,080 But as I say, they I will explain this further. 76 00:04:41,380 --> 00:04:42,700 String not. 77 00:04:44,080 --> 00:04:44,530 This. 78 00:04:45,600 --> 00:04:46,830 Is playable. 79 00:04:49,200 --> 00:04:49,470 Again. 80 00:04:49,470 --> 00:04:51,090 We will copy this. 81 00:04:55,540 --> 00:04:58,270 And we will again create a P here P. 82 00:04:59,640 --> 00:05:03,270 BQ 3.14 and again. 83 00:05:10,180 --> 00:05:12,850 So now our section data is completed. 84 00:05:12,850 --> 00:05:17,620 Now we will also create the section which we will not use. 85 00:05:17,950 --> 00:05:20,050 We will not notice anything here. 86 00:05:20,200 --> 00:05:29,050 Section The main where our main function will live here is section text and we will create a global 87 00:05:29,080 --> 00:05:29,890 main. 88 00:05:30,620 --> 00:05:34,970 Now let's start developing our main function. 89 00:05:34,970 --> 00:05:40,220 So in our main function we will again add the we will push the. 90 00:05:41,170 --> 00:05:42,510 R p. 91 00:05:42,520 --> 00:05:43,330 P. 92 00:05:44,240 --> 00:05:47,150 This is the function prologue. 93 00:05:47,190 --> 00:05:48,170 Actually, we can. 94 00:05:50,770 --> 00:05:53,500 Less taps, though, because we will not have. 95 00:05:55,820 --> 00:05:56,750 The strings here. 96 00:05:57,620 --> 00:05:59,360 These are just instructions. 97 00:05:59,480 --> 00:06:01,670 So here, this is the. 98 00:06:03,610 --> 00:06:05,860 Function prologue. 99 00:06:08,680 --> 00:06:09,190 Move. 100 00:06:11,180 --> 00:06:13,520 Our BP RSP. 101 00:06:13,550 --> 00:06:16,580 This is, again, a function prologue as well. 102 00:06:19,140 --> 00:06:19,950 Move. 103 00:06:22,760 --> 00:06:23,360 One. 104 00:06:25,510 --> 00:06:27,070 I always add this here. 105 00:06:39,600 --> 00:06:40,020 Here. 106 00:06:40,020 --> 00:06:45,510 So Rex1 is as we did in previous lectures. 107 00:06:45,510 --> 00:06:48,060 This is for right writing here. 108 00:06:48,450 --> 00:06:50,100 One is right. 109 00:06:50,700 --> 00:06:53,070 And we will again move here. 110 00:06:53,430 --> 00:06:54,210 Ready? 111 00:06:55,340 --> 00:06:59,960 As for to write on the console. 112 00:07:04,080 --> 00:07:05,970 To STD out. 113 00:07:06,990 --> 00:07:07,190 Out. 114 00:07:07,200 --> 00:07:07,650 Out here. 115 00:07:07,650 --> 00:07:08,700 So move. 116 00:07:09,880 --> 00:07:11,080 RSI. 117 00:07:12,520 --> 00:07:13,420 Message one. 118 00:07:13,420 --> 00:07:14,740 First, we will use this message. 119 00:07:14,740 --> 00:07:15,240 One. 120 00:07:15,250 --> 00:07:16,300 So this is the. 121 00:07:19,730 --> 00:07:23,660 String to display and after that. 122 00:07:25,510 --> 00:07:26,490 We will again. 123 00:07:26,500 --> 00:07:27,520 We will move. 124 00:07:30,720 --> 00:07:32,310 Are the eggs. 125 00:07:32,550 --> 00:07:39,870 And after that we will again print the length of this message one string, and after that we will apply 126 00:07:39,870 --> 00:07:42,480 the same for the message to here. 127 00:07:42,750 --> 00:07:44,820 Message one length. 128 00:07:44,850 --> 00:07:45,540 Here. 129 00:07:47,690 --> 00:07:49,100 This is the length. 130 00:07:50,820 --> 00:07:53,070 Of the string here. 131 00:07:53,070 --> 00:07:56,160 Actually, we let's actually add tabs. 132 00:07:57,180 --> 00:07:58,410 More tabs here. 133 00:07:59,640 --> 00:08:02,370 Doesn't look good here for display purposes. 134 00:08:03,550 --> 00:08:04,960 And that's it. 135 00:08:04,970 --> 00:08:09,260 After that, we will call the syscall to display the string. 136 00:08:09,280 --> 00:08:10,960 Display the string. 137 00:08:10,960 --> 00:08:12,760 So these are the comments, as you know. 138 00:08:14,280 --> 00:08:17,010 So we will again instead of writing. 139 00:08:17,040 --> 00:08:19,830 Actually we can write it out here. 140 00:08:19,830 --> 00:08:24,180 So rax one, it's for one. 141 00:08:25,010 --> 00:08:25,940 Right. 142 00:08:26,930 --> 00:08:28,310 Of the I. 143 00:08:30,240 --> 00:08:35,940 Are thy one is for the STD out. 144 00:08:39,470 --> 00:08:41,120 STD out. 145 00:08:43,190 --> 00:08:44,390 And after that. 146 00:08:45,030 --> 00:08:45,600 It's called. 147 00:08:48,860 --> 00:08:54,440 Tracks RDA and after that we will need to add RSA again. 148 00:08:54,560 --> 00:08:55,880 Message to. 149 00:08:56,950 --> 00:09:02,620 Um, this is the string to display and move again. 150 00:09:02,650 --> 00:09:04,420 Ah, the X. 151 00:09:04,840 --> 00:09:07,870 This is the message to Len. 152 00:09:08,590 --> 00:09:11,980 And again, this is the length of the string. 153 00:09:12,220 --> 00:09:15,610 Length of the string. 154 00:09:19,380 --> 00:09:20,520 Length out a string. 155 00:09:21,240 --> 00:09:21,960 And. 156 00:09:24,580 --> 00:09:25,420 After that. 157 00:09:25,420 --> 00:09:26,190 That's it. 158 00:09:26,200 --> 00:09:26,890 We will. 159 00:09:28,530 --> 00:09:29,960 You can call the syscall. 160 00:09:31,790 --> 00:09:33,500 So this is for. 161 00:09:34,710 --> 00:09:40,870 Displaying this string again, the second string which is kicking in the live display. 162 00:09:40,890 --> 00:09:48,000 So you might be wondering where we will use this radius and pi here, which we will use that right now. 163 00:09:51,110 --> 00:09:54,350 And this is the skull is display. 164 00:09:55,430 --> 00:09:57,290 The ring. 165 00:09:58,770 --> 00:10:03,690 And after that, this is the last year, so we will develop the function. 166 00:10:03,690 --> 00:10:04,470 Epilogue. 167 00:10:04,620 --> 00:10:05,100 Function. 168 00:10:05,100 --> 00:10:05,590 Epilogue. 169 00:10:05,610 --> 00:10:09,300 Again, we will add exit and success exit code again. 170 00:10:09,300 --> 00:10:13,980 And after that we will again call the syscall to quit the program. 171 00:10:13,980 --> 00:10:14,490 Right. 172 00:10:14,490 --> 00:10:15,300 So. 173 00:10:16,360 --> 00:10:20,880 After calling the Siskel here again, we will call it one more time. 174 00:10:20,890 --> 00:10:28,150 After completing these four lines of code, we will firstly create a two function epilogue Our BP. 175 00:10:29,840 --> 00:10:31,760 Are here. 176 00:10:32,480 --> 00:10:33,320 Cases here. 177 00:10:37,990 --> 00:10:38,910 Bob, I. 178 00:10:38,950 --> 00:10:39,370 Okay. 179 00:10:39,370 --> 00:10:40,630 You can't hear my voice. 180 00:10:40,990 --> 00:10:41,360 Okay. 181 00:10:41,620 --> 00:10:42,130 Beep. 182 00:10:42,730 --> 00:10:43,540 I just scared. 183 00:10:43,540 --> 00:10:47,530 I thought this ten minutes of work just for nothing. 184 00:10:48,530 --> 00:10:50,030 And here are BP. 185 00:10:50,540 --> 00:10:53,360 This is the function epilogue. 186 00:10:54,700 --> 00:10:56,850 And again move RB. 187 00:10:58,200 --> 00:11:02,550 Here are BP again without the BP. 188 00:11:02,580 --> 00:11:03,780 Here just BP. 189 00:11:05,030 --> 00:11:08,680 This is the function epilogue as well. 190 00:11:08,690 --> 00:11:14,450 And after that we will move the racks which we did in previous code here. 191 00:11:14,450 --> 00:11:20,360 This is for the 60 means exit, and after that we will again call. 192 00:11:20,360 --> 00:11:31,250 Lastly, rest instruction is called RDA and this is for the zero, which is the success exit code as. 193 00:11:32,040 --> 00:11:34,200 Exit code and after that. 194 00:11:36,170 --> 00:11:37,130 Port here. 195 00:11:37,130 --> 00:11:40,140 And after that we will call the syscall. 196 00:11:40,160 --> 00:11:41,660 And that's. 197 00:11:42,490 --> 00:11:43,540 Uh, quit. 198 00:11:43,750 --> 00:11:44,500 This is just a quick. 199 00:11:44,500 --> 00:11:45,930 So our program is done. 200 00:11:45,940 --> 00:11:54,550 So this type of programming to your, uh, you can write it in your, um, favorite editor and save 201 00:11:54,580 --> 00:11:56,260 as kicking the ACM. 202 00:11:56,260 --> 00:12:01,090 And now in next lecture, we will create the make file here. 203 00:12:01,090 --> 00:12:03,250 So I'm waiting you in next lecture.