1 00:00:01,060 --> 00:00:03,970 Hello, everyone, and welcome to today's video lecture. 2 00:00:03,970 --> 00:00:10,150 In this session, we are going to dive deep into an assembly code example that calculates the sum of 3 00:00:10,150 --> 00:00:13,000 numbers from zero to a given value. 4 00:00:13,030 --> 00:00:19,990 Using a loop construct, we will walk you through the code step by step, discussing how registers, 5 00:00:19,990 --> 00:00:25,840 loops and external functions work together to achieve the desired goal and result. 6 00:00:25,840 --> 00:00:29,500 And here in previous lecture, we just have some typo here. 7 00:00:29,500 --> 00:00:31,090 Let's quickly fix that. 8 00:00:31,120 --> 00:00:37,450 I fix that when I shared the previous lecture code in attachment sections, but I want to fix that. 9 00:00:38,430 --> 00:00:39,330 Uh, here. 10 00:00:39,360 --> 00:00:40,560 Uh, also here. 11 00:00:41,100 --> 00:00:47,060 And let's start by taking a look at the assembly code we will be exploring today. 12 00:00:47,070 --> 00:00:52,620 As you can see on the screen, we have a complete assembly program that calculates a sum of numbers 13 00:00:52,620 --> 00:00:54,120 using a loop. 14 00:00:54,120 --> 00:01:03,330 So the loop construct is quite interesting as it utilizes the RC x register. 15 00:01:04,410 --> 00:01:08,490 So the RC x register as a loop counter. 16 00:01:08,490 --> 00:01:12,960 So automatically decrementing with each iteration. 17 00:01:12,960 --> 00:01:18,630 So before we compile and run the code, let's break down the key components of the program. 18 00:01:18,630 --> 00:01:23,970 So we have a number variable that is initially set to five. 19 00:01:24,060 --> 00:01:27,330 This is the upper limit of our summation. 20 00:01:27,330 --> 00:01:35,040 We are using the printf function to display the calculated sum and the program initializes the loop 21 00:01:35,040 --> 00:01:47,530 counter rc x and an accumulator rax to perform the summation and the loop instruction decrements the 22 00:01:47,530 --> 00:01:53,170 loop counter and repeats the loop by the until the counter becomes zero. 23 00:01:53,170 --> 00:01:56,890 And now let's compile and run the code. 24 00:01:56,900 --> 00:01:59,860 Open your terminal here. 25 00:02:00,940 --> 00:02:03,190 Uh, go to the pod here. 26 00:02:04,280 --> 00:02:05,360 We should have instruction. 27 00:02:05,490 --> 00:02:07,850 Yes, the instruction flags. 28 00:02:07,850 --> 00:02:12,920 And here we have project as actually just let's remove the previous Mac file. 29 00:02:13,760 --> 00:02:18,530 And as you can see, we just only have this ESM file here. 30 00:02:18,530 --> 00:02:22,000 Let's read it Project Dot RSM. 31 00:02:22,010 --> 00:02:24,830 And as you can see, this is our codes that we wrote. 32 00:02:24,830 --> 00:02:26,410 We wrote in previous lecture. 33 00:02:26,420 --> 00:02:28,820 Now what we're going to do is we will create the. 34 00:02:30,270 --> 00:02:32,430 Make file so mousepad. 35 00:02:32,460 --> 00:02:33,780 Make file. 36 00:02:34,290 --> 00:02:42,750 And in this make file we will first add the command like make make file for the project dot ASM and 37 00:02:42,750 --> 00:02:43,350 project. 38 00:02:43,350 --> 00:02:45,930 Here we will make this to. 39 00:02:46,680 --> 00:02:51,930 Project all here and use, we will use the GCC output. 40 00:02:55,050 --> 00:02:56,270 All right from here. 41 00:02:57,000 --> 00:02:58,440 For project. 42 00:02:58,740 --> 00:03:00,710 We will use the GCC. 43 00:03:00,720 --> 00:03:01,530 GCC. 44 00:03:07,130 --> 00:03:11,640 Project project that will use no Pi. 45 00:03:13,170 --> 00:03:16,230 And project that all here. 46 00:03:17,070 --> 00:03:17,360 Roar. 47 00:03:17,960 --> 00:03:18,600 Roar. 48 00:03:20,190 --> 00:03:23,400 Project that ESM will use. 49 00:03:23,710 --> 00:03:24,990 NSM here. 50 00:03:25,830 --> 00:03:29,010 Elf 64 bit and some 64 bit here. 51 00:03:30,220 --> 00:03:35,700 F 64 G Uppercase L Uppercase F. 52 00:03:36,690 --> 00:03:38,450 Dwarf format. 53 00:03:39,690 --> 00:03:46,260 And project that ESM and we will also the listing here project that. 54 00:03:47,550 --> 00:03:49,110 Project list. 55 00:03:49,290 --> 00:03:51,070 And that's it. 56 00:03:51,090 --> 00:03:52,830 Let's close this now. 57 00:03:52,830 --> 00:03:55,820 Just write the make. 58 00:03:55,830 --> 00:03:57,930 And as you can see here, our program is. 59 00:03:58,890 --> 00:04:01,320 Compiled and linked and assembled here. 60 00:04:01,500 --> 00:04:05,100 And as you can see, we have this project, right? 61 00:04:05,250 --> 00:04:06,600 And now. 62 00:04:07,610 --> 00:04:13,700 Well, once compiled, we can execute the program by running the dot slash project. 63 00:04:13,850 --> 00:04:18,860 And as you can see, the sum from 0 to 5 is 15. 64 00:04:18,860 --> 00:04:21,980 So the that's it here. 65 00:04:22,100 --> 00:04:26,120 This is not so basic because we will also change the numbers. 66 00:04:26,120 --> 00:04:29,090 So now comes the exciting part. 67 00:04:29,120 --> 00:04:37,130 Now let's see how changing number value affects the program's execution and currently this number. 68 00:04:39,860 --> 00:04:40,180 Um. 69 00:04:40,340 --> 00:04:42,050 Yes, this number. 70 00:04:43,360 --> 00:04:44,770 Is set to five. 71 00:04:44,800 --> 00:04:48,730 Now let's change to the larger value. 72 00:04:49,140 --> 00:04:50,620 Uh, something, let's say. 73 00:04:51,640 --> 00:04:52,560 10 million. 74 00:04:52,570 --> 00:04:53,230 Ten. 75 00:04:55,540 --> 00:04:55,990 Here. 76 00:04:56,860 --> 00:04:57,700 And. 77 00:04:58,620 --> 00:05:02,250 Now let's make again and make. 78 00:05:06,790 --> 00:05:07,450 Project. 79 00:05:07,450 --> 00:05:13,100 And as you can see, the sound from 0 to 10 million is something like that, right? 80 00:05:13,120 --> 00:05:20,440 So now we save the saved the file compiled it, and now we can also observe the execution time. 81 00:05:20,440 --> 00:05:25,210 So before we run the program, let's discuss an experiment. 82 00:05:25,210 --> 00:05:33,010 So you can also use the time command in Linux to measure the execution time of the program. 83 00:05:33,160 --> 00:05:36,430 For instance, the Time project. 84 00:05:36,430 --> 00:05:43,780 And as you can see, execution time, the sum of sum from 0 to 1 million is something good. 85 00:05:44,110 --> 00:05:46,210 And here let's actually. 86 00:05:47,240 --> 00:05:50,600 This sum from 0 to 1 million, 1 million. 87 00:05:50,600 --> 00:05:53,180 But we also have this five, right? 88 00:05:53,180 --> 00:05:56,600 Let's actually check with this five again. 89 00:05:58,700 --> 00:06:03,320 As we opened the Oh no, we can't close this because the Sims is open here. 90 00:06:03,320 --> 00:06:07,430 So here, make again time. 91 00:06:09,330 --> 00:06:10,290 Project. 92 00:06:10,470 --> 00:06:11,940 We will note it down here. 93 00:06:12,630 --> 00:06:14,670 The psalm from here. 94 00:06:15,920 --> 00:06:23,750 As you can see here, the value gets bigger and our time is gets bigger, too. 95 00:06:26,080 --> 00:06:26,350 Here. 96 00:06:26,350 --> 00:06:28,540 Let's actually try 10 trillion. 97 00:06:35,540 --> 00:06:38,030 Now let's compile it again. 98 00:06:39,500 --> 00:06:40,220 Make. 99 00:06:41,620 --> 00:06:42,310 Time. 100 00:06:44,170 --> 00:06:45,130 Project. 101 00:06:46,490 --> 00:06:50,690 And as you can see here, let's give us some example here. 102 00:06:51,240 --> 00:06:53,150 Yeah, we are still waiting for it. 103 00:06:57,030 --> 00:07:03,750 And as you can see here, it's almost 20s to 12 seconds here, not 20. 104 00:07:04,020 --> 00:07:06,930 Now, we will this is for. 105 00:07:10,030 --> 00:07:10,600 This. 106 00:07:12,430 --> 00:07:12,910 Yes. 107 00:07:13,030 --> 00:07:15,310 So this is for 10 million. 108 00:07:15,780 --> 00:07:16,060 It did. 109 00:07:16,210 --> 00:07:22,150 It couldn't calculate because we reached the limits of our registers. 110 00:07:23,810 --> 00:07:24,680 Now. 111 00:07:25,540 --> 00:07:28,860 Let's even add six zeros. 112 00:07:28,870 --> 00:07:30,100 One, two, three. 113 00:07:30,310 --> 00:07:31,540 One, two, three. 114 00:07:31,720 --> 00:07:32,320 Here. 115 00:07:32,650 --> 00:07:34,480 Now let's test it with it. 116 00:07:36,360 --> 00:07:38,520 I'll ask Claire make. 117 00:07:39,930 --> 00:07:41,280 And time. 118 00:07:44,710 --> 00:07:45,550 Project. 119 00:07:58,000 --> 00:07:58,590 It might. 120 00:07:58,600 --> 00:08:01,780 I think it might take, like, more than. 121 00:08:02,910 --> 00:08:05,580 30s or 20s. 122 00:08:05,850 --> 00:08:06,630 Let's see. 123 00:08:09,630 --> 00:08:15,600 Also consider this like I'm running this operating system in my virtual machine. 124 00:08:17,160 --> 00:08:21,540 My CPU is Intel i7. 125 00:08:21,570 --> 00:08:23,820 The 10th generation. 126 00:08:25,470 --> 00:08:26,250 Let's see. 127 00:08:30,000 --> 00:08:32,390 Many times take here. 128 00:08:42,030 --> 00:08:42,310 Is it? 129 00:08:43,000 --> 00:08:43,570 No. 130 00:08:43,590 --> 00:08:45,840 So here, as you can see here, the. 131 00:08:47,950 --> 00:08:51,280 The sum from 0 to 5 is 15. 132 00:08:51,310 --> 00:08:55,990 The real is 0.003 seconds. 133 00:08:56,020 --> 00:09:07,490 The sum from 0 to 10 million is 0.0 16 seconds and the sum from 0 to 10. 134 00:09:07,960 --> 00:09:08,600 Yeah, it it. 135 00:09:08,770 --> 00:09:11,080 No, it was 10 billion, I think. 136 00:09:11,080 --> 00:09:11,590 Yeah. 137 00:09:14,070 --> 00:09:14,370 Yeah. 138 00:09:14,370 --> 00:09:14,850 Ten. 139 00:09:18,890 --> 00:09:28,070 Yeah, ten is some from uh, 0 to 10 billion is something like, uh, 11.944. 140 00:09:29,260 --> 00:09:31,240 Seconds now. 141 00:09:31,930 --> 00:09:33,550 We are still waiting for it. 142 00:09:34,540 --> 00:09:39,850 So our program will give us give us some output here. 143 00:09:39,970 --> 00:09:45,460 We just reached I think we reached the limits of our virtual machine processing unit. 144 00:09:45,460 --> 00:09:52,210 So this, um, Kali Linux here is installed on the virtual machine here. 145 00:09:52,210 --> 00:09:54,700 And as you can see here, it's 64 bit. 146 00:09:56,490 --> 00:09:56,970 Yeah. 147 00:09:57,060 --> 00:10:01,230 Love 11th generation Intel core i5. 148 00:10:02,500 --> 00:10:02,830 11. 149 00:10:02,830 --> 00:10:03,660 11. 150 00:10:03,670 --> 00:10:04,510 11. 151 00:10:04,510 --> 00:10:05,180 Four. 152 00:10:05,200 --> 00:10:05,640 No. 153 00:10:05,650 --> 00:10:06,070 11. 154 00:10:06,250 --> 00:10:08,350 I5 11 400. 155 00:10:08,400 --> 00:10:09,040 H. 156 00:10:10,450 --> 00:10:18,940 The GPU and memory is I gave eight memory from my 16 gigabyte ram. 157 00:10:21,630 --> 00:10:23,170 We are still waiting here. 158 00:10:23,620 --> 00:10:26,170 We can also check the processes here. 159 00:10:29,380 --> 00:10:37,750 And as you can see here, this project almost takes 25% of our CPU power. 160 00:10:37,900 --> 00:10:41,560 And here we are still waiting for it. 161 00:10:45,290 --> 00:10:52,460 Like were literally Chrome takes 0% and this takes 26% of our CPU power. 162 00:10:55,310 --> 00:10:56,120 The sexual check. 163 00:11:06,770 --> 00:11:13,430 Yeah, it might take, uh, the, uh, like days to compile complete this because my, uh, virtual 164 00:11:13,430 --> 00:11:15,590 machine is pretty slow in this case. 165 00:11:16,130 --> 00:11:22,360 Maybe we should try this on this native, uh, operating system here, but it doesn't matter. 166 00:11:22,370 --> 00:11:29,450 As you can see, by changing the number value, we can explore how the program behaves with different 167 00:11:29,450 --> 00:11:30,080 inputs. 168 00:11:30,080 --> 00:11:37,270 So this exercise showcases the power of assembly language in understanding low level computer operations. 169 00:11:37,280 --> 00:11:43,010 I hope you found this video lecture insightful and educational, and thank you for watching and feel 170 00:11:43,010 --> 00:11:43,370 free. 171 00:11:43,400 --> 00:11:51,620 Feel free to adjust the script as needed to match your style and preferences and good luck.