WEBVTT

00:01.060 --> 00:03.970
Hello, everyone, and welcome to today's video lecture.

00:03.970 --> 00:10.150
In this session, we are going to dive deep into an assembly code example that calculates the sum of

00:10.150 --> 00:13.000
numbers from zero to a given value.

00:13.030 --> 00:19.990
Using a loop construct, we will walk you through the code step by step, discussing how registers,

00:19.990 --> 00:25.840
loops and external functions work together to achieve the desired goal and result.

00:25.840 --> 00:29.500
And here in previous lecture, we just have some typo here.

00:29.500 --> 00:31.090
Let's quickly fix that.

00:31.120 --> 00:37.450
I fix that when I shared the previous lecture code in attachment sections, but I want to fix that.

00:38.430 --> 00:39.330
Uh, here.

00:39.360 --> 00:40.560
Uh, also here.

00:41.100 --> 00:47.060
And let's start by taking a look at the assembly code we will be exploring today.

00:47.070 --> 00:52.620
As you can see on the screen, we have a complete assembly program that calculates a sum of numbers

00:52.620 --> 00:54.120
using a loop.

00:54.120 --> 01:03.330
So the loop construct is quite interesting as it utilizes the RC x register.

01:04.410 --> 01:08.490
So the RC x register as a loop counter.

01:08.490 --> 01:12.960
So automatically decrementing with each iteration.

01:12.960 --> 01:18.630
So before we compile and run the code, let's break down the key components of the program.

01:18.630 --> 01:23.970
So we have a number variable that is initially set to five.

01:24.060 --> 01:27.330
This is the upper limit of our summation.

01:27.330 --> 01:35.040
We are using the printf function to display the calculated sum and the program initializes the loop

01:35.040 --> 01:47.530
counter rc x and an accumulator rax to perform the summation and the loop instruction decrements the

01:47.530 --> 01:53.170
loop counter and repeats the loop by the until the counter becomes zero.

01:53.170 --> 01:56.910
And now let's compile and run the code.

01:56.920 --> 01:59.860
Open your terminal here.

02:00.940 --> 02:03.190
Uh, go to the pod here.

02:04.280 --> 02:05.360
We should have instruction.

02:05.490 --> 02:07.850
Yes, the instruction flags.

02:07.850 --> 02:12.920
And here we have project as actually just let's remove the previous Mac file.

02:13.760 --> 02:18.530
And as you can see, we just only have this ESM file here.

02:18.530 --> 02:22.000
Let's read it Project Dot RSM.

02:22.010 --> 02:24.760
And as you can see, this is our codes that we wrote.

02:24.830 --> 02:26.410
We wrote in previous lecture.

02:26.420 --> 02:28.820
Now what we're going to do is we will create the.

02:30.270 --> 02:32.430
Make file so mousepad.

02:32.460 --> 02:33.780
Make file.

02:34.290 --> 02:42.750
And in this make file we will first add the command like make make file for the project dot ASM and

02:42.750 --> 02:43.350
project.

02:43.350 --> 02:45.930
Here we will make this to.

02:46.680 --> 02:51.930
Project all here and use, we will use the GCC output.

02:55.050 --> 02:56.270
All right from here.

02:57.000 --> 02:58.440
For project.

02:58.740 --> 03:00.710
We will use the GCC.

03:00.720 --> 03:01.530
GCC.

03:07.130 --> 03:11.640
Project project that will use no Pi.

03:13.170 --> 03:16.230
And project that all here.

03:17.940 --> 03:18.600
Roar.

03:20.190 --> 03:23.400
Project that ESM will use.

03:23.660 --> 03:24.990
NSM here.

03:25.830 --> 03:29.010
Elf 64 bit and some 64 bit here.

03:30.220 --> 03:35.700
F 64 G Uppercase L Uppercase F.

03:36.690 --> 03:38.450
Dwarf format.

03:39.690 --> 03:46.260
And project that ESM and we will also the listing here project that.

03:47.550 --> 03:49.110
Project list.

03:49.290 --> 03:51.070
And that's it.

03:51.090 --> 03:52.830
Let's close this now.

03:52.830 --> 03:55.820
Just write the make.

03:55.830 --> 03:57.930
And as you can see here, our program is.

03:58.890 --> 04:01.320
Compiled and linked and assembled here.

04:01.500 --> 04:05.100
And as you can see, we have this project, right?

04:05.250 --> 04:06.600
And now.

04:07.610 --> 04:13.700
Well, once compiled, we can execute the program by running the dot slash project.

04:13.850 --> 04:18.860
And as you can see, the sum from 0 to 5 is 15.

04:18.860 --> 04:21.980
So the that's it here.

04:22.100 --> 04:26.120
This is not so basic because we will also change the numbers.

04:26.120 --> 04:29.090
So now comes the exciting part.

04:29.120 --> 04:37.130
Now let's see how changing number value affects the program's execution and currently this number.

04:39.860 --> 04:40.180
Um.

04:40.340 --> 04:42.050
Yes, this number.

04:43.360 --> 04:44.770
Is set to five.

04:44.800 --> 04:48.730
Now let's change to the larger value.

04:49.120 --> 04:50.620
Uh, something, let's say.

04:51.640 --> 04:52.560
10 million.

04:52.570 --> 04:53.230
Ten.

04:55.540 --> 04:55.990
Here.

04:56.860 --> 04:57.700
And.

04:58.620 --> 05:02.250
Now let's make again and make.

05:06.790 --> 05:07.450
Project.

05:07.450 --> 05:13.100
And as you can see, the sound from 0 to 10 million is something like that, right?

05:13.120 --> 05:20.440
So now we save the saved the file compiled it, and now we can also observe the execution time.

05:20.440 --> 05:25.210
So before we run the program, let's discuss an experiment.

05:25.210 --> 05:33.010
So you can also use the time command in Linux to measure the execution time of the program.

05:33.160 --> 05:36.430
For instance, the Time project.

05:36.430 --> 05:43.780
And as you can see, execution time, the sum of sum from 0 to 1 million is something good.

05:44.110 --> 05:46.210
And here let's actually.

05:47.240 --> 05:50.600
This sum from 0 to 1 million, 1 million.

05:50.600 --> 05:53.180
But we also have this five, right?

05:53.180 --> 05:56.600
Let's actually check with this five again.

05:58.700 --> 06:03.320
As we opened the Oh no, we can't close this because the Sims is open here.

06:03.320 --> 06:07.430
So here, make again time.

06:09.330 --> 06:10.290
Project.

06:10.470 --> 06:11.940
We will note it down here.

06:12.630 --> 06:14.670
The psalm from here.

06:15.920 --> 06:23.750
As you can see here, the value gets bigger and our time is gets bigger, too.

06:26.080 --> 06:26.350
Here.

06:26.350 --> 06:28.540
Let's actually try 10 trillion.

06:35.540 --> 06:38.030
Now let's compile it again.

06:39.500 --> 06:40.220
Make.

06:41.620 --> 06:42.310
Time.

06:44.170 --> 06:45.130
Project.

06:46.490 --> 06:50.690
And as you can see here, let's give us some example here.

06:51.240 --> 06:53.150
Yeah, we are still waiting for it.

06:57.030 --> 07:03.750
And as you can see here, it's almost 20s to 12 seconds here, not 20.

07:04.020 --> 07:06.930
Now, we will this is for.

07:10.030 --> 07:10.600
This.

07:12.430 --> 07:12.910
Yes.

07:13.030 --> 07:15.310
So this is for 10 million.

07:15.780 --> 07:16.060
It did.

07:16.210 --> 07:22.150
It couldn't calculate because we reached the limits of our registers.

07:23.810 --> 07:24.680
Now.

07:25.540 --> 07:28.860
Let's even add six zeros.

07:28.870 --> 07:30.100
One, two, three.

07:30.310 --> 07:31.540
One, two, three.

07:31.720 --> 07:32.320
Here.

07:32.650 --> 07:34.480
Now let's test it with it.

07:36.360 --> 07:38.520
I'll ask Claire make.

07:39.930 --> 07:41.280
And time.

07:44.710 --> 07:45.550
Project.

07:58.000 --> 07:58.590
It might.

07:58.600 --> 08:01.780
I think it might take, like, more than.

08:02.910 --> 08:05.580
30s or 20s.

08:05.850 --> 08:06.630
Let's see.

08:09.630 --> 08:15.600
Also consider this like I'm running this operating system in my virtual machine.

08:17.160 --> 08:21.540
My CPU is Intel i7.

08:21.570 --> 08:23.820
The 10th generation.

08:25.470 --> 08:26.250
Let's see.

08:30.000 --> 08:32.390
Many times take here.

08:42.030 --> 08:42.310
Is it?

08:43.000 --> 08:43.570
No.

08:43.590 --> 08:45.840
So here, as you can see here, the.

08:47.950 --> 08:51.280
The sum from 0 to 5 is 15.

08:51.310 --> 08:55.990
The real is 0.003 seconds.

08:56.020 --> 09:07.500
The sum from 0 to 10 million is 0.0 16 seconds and the sum from 0 to 10.

09:07.960 --> 09:08.600
Yeah, it it.

09:08.770 --> 09:11.080
No, it was 10 billion, I think.

09:11.080 --> 09:11.590
Yeah.

09:14.070 --> 09:14.370
Yeah.

09:14.370 --> 09:14.850
Ten.

09:18.890 --> 09:28.070
Yeah, ten is some from uh, 0 to 10 billion is something like, uh, 11.944.

09:29.260 --> 09:31.240
Seconds now.

09:31.930 --> 09:33.550
We are still waiting for it.

09:34.540 --> 09:39.850
So our program will give us give us some output here.

09:39.970 --> 09:45.460
We just reached I think we reached the limits of our virtual machine processing unit.

09:45.460 --> 09:52.210
So this, um, Kali Linux here is installed on the virtual machine here.

09:52.210 --> 09:54.700
And as you can see here, it's 64 bit.

09:56.490 --> 09:56.970
Yeah.

09:57.060 --> 10:01.230
Love 11th generation Intel core i5.

10:02.500 --> 10:02.830
11.

10:02.830 --> 10:03.660
11.

10:03.670 --> 10:04.510
11.

10:04.510 --> 10:05.180
Four.

10:05.200 --> 10:05.640
No.

10:05.650 --> 10:06.070
11.

10:06.250 --> 10:08.350
I5 11 400.

10:08.400 --> 10:09.040
H.

10:10.450 --> 10:18.940
The GPU and memory is I gave eight memory from my 16 gigabyte ram.

10:21.630 --> 10:23.170
We are still waiting here.

10:23.620 --> 10:26.170
We can also check the processes here.

10:29.380 --> 10:37.750
And as you can see here, this project almost takes 25% of our CPU power.

10:37.900 --> 10:41.560
And here we are still waiting for it.

10:45.290 --> 10:52.460
Like were literally Chrome takes 0% and this takes 26% of our CPU power.

10:55.310 --> 10:56.120
The sexual check.

11:06.770 --> 11:13.430
Yeah, it might take, uh, the, uh, like days to compile complete this because my, uh, virtual

11:13.430 --> 11:15.590
machine is pretty slow in this case.

11:16.130 --> 11:22.360
Maybe we should try this on this native, uh, operating system here, but it doesn't matter.

11:22.370 --> 11:29.450
As you can see, by changing the number value, we can explore how the program behaves with different

11:29.450 --> 11:30.080
inputs.

11:30.080 --> 11:37.270
So this exercise showcases the power of assembly language in understanding low level computer operations.

11:37.280 --> 11:43.010
I hope you found this video lecture insightful and educational, and thank you for watching and feel

11:43.010 --> 11:43.370
free.

11:43.400 --> 11:51.620
Feel free to adjust the script as needed to match your style and preferences and good luck.
