WEBVTT

00:00.310 --> 00:01.990
And now that's it.

00:02.110 --> 00:05.600
We have completed our program and it's running, as you can see.

00:05.650 --> 00:09.820
We just have some like, uh, three typos here.

00:10.210 --> 00:16.190
As you can see here in line 7109 and 135.

00:16.210 --> 00:17.410
So I already fix that.

00:17.410 --> 00:21.120
And just the regular typos here like a.

00:22.490 --> 00:28.730
Are as all Thai here, like the 1 or 2 keyword typos I fixed it with here.

00:28.730 --> 00:29.570
Now it's fixed.

00:29.570 --> 00:30.950
As you can see, it's running.

00:30.980 --> 00:33.230
I also, uh, the.

00:34.360 --> 00:36.070
Publish the fixed one here.

00:36.070 --> 00:37.410
That is not a big deal.

00:37.420 --> 00:44.650
Now, in this lecture, what you're going to learn is you will learn all of the registers and the.

00:45.650 --> 00:50.210
I will explain all of the things that we did in this code here.

00:50.210 --> 00:55.100
And as you can see, it's almost 150 lines of code.

00:55.280 --> 00:56.300
So.

00:57.580 --> 01:01.750
Now let's start from the assembly.

01:04.610 --> 01:10.790
The start from the increment here because we already explained the previously code.

01:10.820 --> 01:13.010
Here before the increment.

01:14.790 --> 01:16.710
So here we have increment, right?

01:16.710 --> 01:17.490
So.

01:18.680 --> 01:21.860
We are using the as a first assembly here.

01:21.860 --> 01:24.740
We are using the this instruction here.

01:24.740 --> 01:30.650
This instruction moves the value stored in the memory location referred as number one into the Rax register

01:30.650 --> 01:35.270
and it's loading the value of number one into the register for manipulation.

01:35.270 --> 01:41.150
And I see here this is the instruction here.

01:41.180 --> 01:48.380
This increments the value in the rax register by one, and in this case it's incrementing the value

01:48.380 --> 01:50.450
of number one by one.

01:50.450 --> 01:56.060
Here, as you can see here, it was 1 to 8 and now it's 129.

01:56.060 --> 01:56.630
Right.

01:56.720 --> 02:04.250
And here we also have move result i rax this is this instruction moves the value in the rax register

02:04.250 --> 02:11.690
which now holds the incremented value to the memory location pointed to by result i and it stores the

02:11.690 --> 02:13.940
result of increment operation.

02:14.120 --> 02:17.750
And here we are displaying the results in this case.

02:17.870 --> 02:18.720
So.

02:19.760 --> 02:26.330
The RDA register is loaded with the memory address of the format string fmt integer.

02:26.330 --> 02:32.510
So this string will be used in the printf function to format the output.

02:32.630 --> 02:38.090
And we also have the RSI and C here in C.

02:38.480 --> 02:43.940
So this RSI register is loaded with the memory address of the message string in C here.

02:43.940 --> 02:50.600
So this message will be used in the printf function to provide context for the displayed result.

02:50.600 --> 02:52.640
I want to also here.

03:00.510 --> 03:01.530
As you can see, it's tradition.

03:01.530 --> 03:02.700
Number one, incremented.

03:03.630 --> 03:08.840
And also we have move the result.

03:08.890 --> 03:14.970
I hear the RDX register is loaded with the value stored in the memory location pointed to by result

03:15.000 --> 03:15.180
I.

03:15.210 --> 03:22.140
So this value represents the result of the incremented operation increment operation and we have the

03:22.140 --> 03:31.440
move rax and this instruction sets the value of Rax register to zero and it prepares Rax to be used

03:31.440 --> 03:36.750
as the return value when the printf function call is complete.

03:36.750 --> 03:42.420
And this instruction calls the printf function to display the formatted message and the arguments for

03:42.420 --> 03:48.870
the printed functions are loaded into the RTI, RSI and RDX registers.

03:48.870 --> 03:52.710
And we also have the incrementing here.

03:52.710 --> 03:58.980
So similar to before, this instruction moves the value stored in memory location reference by number

03:58.980 --> 04:05.470
one into the Rax register and it's loading the value of number one into the register for manipulation.

04:05.470 --> 04:10.630
And we have the D a C here.

04:11.760 --> 04:18.390
So the the the instruction decrements the value in the rax register by one.

04:18.390 --> 04:23.220
And in this case it's decrementing the value of number one.

04:23.670 --> 04:30.510
And we lastly, we have the result i rax mov result i rax this instruction moves the value in the rax

04:30.510 --> 04:38.070
register register which now holds the decremented value to the memory location pointed to by result

04:38.100 --> 04:42.570
i and it stores the IT stores the result of the decrement operation.

04:42.570 --> 04:45.600
And now we have the displaying the result.

04:45.720 --> 04:46.410
So.

04:47.310 --> 04:55.260
This is basically almost the same as the previous incrementing operation here.

04:56.830 --> 05:01.300
And yeah, the code goes same and same here.

05:01.300 --> 05:06.460
Just changing three registers, instructions and variables.

05:06.460 --> 05:08.440
But the code structure is almost the same.

05:08.440 --> 05:13.330
But here we have the in the display result divide.

05:13.330 --> 05:23.380
And now here we in the shifting code side of the code, we have something interesting here which I will

05:23.380 --> 05:25.840
explain that here.

05:25.840 --> 05:33.070
But we have SA and as a register and sal, we should have somewhere here.

05:34.330 --> 05:35.080
Not division.

05:37.730 --> 05:38.320
Sal.

05:39.770 --> 05:40.550
So.

05:41.940 --> 05:50.640
This instruction moves the value stored in the memory location referenced by a number one into the Rax

05:50.640 --> 05:55.140
register, and it's loading the value of number one into the register for manipulation.

05:55.140 --> 05:58.440
And here we have Sal rax two.

05:58.470 --> 06:09.750
The Sal instruction, also known as c h l this which is meaning the show shift logical shift logical

06:09.750 --> 06:16.770
left shifts the bits of the rax register to the left by two positions, effectively multiplying the

06:16.770 --> 06:19.080
value by two.

06:19.500 --> 06:22.230
And we have the move here.

06:22.260 --> 06:28.890
This instruction moves the value in the tax register which now holds the shifted value to the memory

06:28.890 --> 06:35.610
location pointed to by result I and it stores the result of the left shift operation.

06:36.900 --> 06:41.930
And we us what we have here, we are displaying the result with as we always do.

06:41.940 --> 06:44.280
This is the opposite, opposite for this.

06:44.310 --> 06:44.940
Here we are.

06:44.940 --> 06:49.320
Instead of using Sal, we are using a here.

06:50.530 --> 06:51.280
And.

06:56.250 --> 06:59.880
Yeah, that's it with our program explanation here.

07:01.750 --> 07:05.830
And in next lecture, we will also run this program here.

07:06.340 --> 07:08.080
Explain it, uh, deeper.

07:08.080 --> 07:10.390
And we will analyze this program as well.

07:11.190 --> 07:17.430
And before the closing, stopping this lecture, I want to explain the.

07:18.510 --> 07:19.470
Registers as well.

07:19.470 --> 07:23.430
Again, because we need to repeat it until we.

07:24.710 --> 07:25.610
Know it better.

07:25.610 --> 07:29.090
And I will start with R.D. here.

07:29.090 --> 07:35.000
So this is a general purpose registers often used to hold the address of the format string to be used

07:35.000 --> 07:37.010
with the printf function.

07:37.010 --> 07:41.420
And it is one one of the arguments passed to the functions.

07:41.420 --> 07:42.980
And we also have RSI.

07:43.280 --> 07:47.420
This is a general purpose register also used for holding arguments to function.

07:47.420 --> 07:54.140
And in the code it's utilized to hold the values of numbers or messages that need to be displayed.

07:54.140 --> 07:55.900
And we also have RDX.

07:55.910 --> 08:01.700
This is the general purpose registers as well, often used to hold additional arguments to functions

08:01.700 --> 08:08.330
and in the code it is used to store values such as the result of arithmetic operations before they are

08:08.330 --> 08:09.080
displayed.

08:09.080 --> 08:12.240
And we also have the r BP.

08:12.260 --> 08:17.060
We use that somewhere here r BP here.

08:18.220 --> 08:18.920
Let me find.

08:18.940 --> 08:19.390
Yeah.

08:19.960 --> 08:20.740
RVP.

08:22.100 --> 08:24.450
This is a stack pointer register.

08:24.470 --> 08:31.100
This is points to the top of the stack and it is adjusted to allocate and deallocate memory for local

08:31.100 --> 08:32.960
variables and function calls.

08:33.880 --> 08:43.450
And we have the rags, RTI, RSI, RDX, Rbx and RSP are part of the x86 64 calling convention and are

08:43.450 --> 08:48.910
used to pass arguments and manage function calls between the caller and Callie.

08:49.330 --> 08:59.020
And we also have in C and D, a C here, which we use the incrementing and decrementing operations.

09:01.890 --> 09:03.450
Uh, it should be somewhere here.

09:03.720 --> 09:04.240
I see.

09:04.280 --> 09:10.800
And I see here these instructions, uh, for incrementing and decrementing a register or memory location

09:10.800 --> 09:12.600
by one, respectively.

09:12.600 --> 09:16.680
So they are used to perform simple arithmetic operations quickly.

09:17.040 --> 09:22.380
We have the add and sub here.

09:23.440 --> 09:30.130
This instruction that adds a value to a register or memory location, and it is used for addition parents

09:30.130 --> 09:31.060
and for sub.

09:31.060 --> 09:37.270
Here is this instruction that subtracts a value from a register or memory location and it is used for

09:37.270 --> 09:49.180
subtraction operations and we also have s a L and s r a s a r here, which should be somewhere.

09:50.700 --> 09:54.360
Here's are s a are here and.

09:55.280 --> 09:55.850
Sal.

09:57.320 --> 10:03.350
So these are the shift arithmetic left and shift arithmetic right instructions are used for shifting

10:03.350 --> 10:08.720
the bits of registers or memory location to the left or right, and they can be used for multiplication

10:08.720 --> 10:12.050
and division by powers of two respectively.

10:12.050 --> 10:20.840
And we also have here I'm u l you should see somewhere here instruction use.

10:20.840 --> 10:24.440
This instruction is used for sine multiplication of two values.

10:24.440 --> 10:32.060
It is often used with two operands and the result is stored in the destination operand.

10:32.670 --> 10:34.190
And we have it here.

10:34.200 --> 10:39.660
This is this instruction used for sign division and it divides the contents of the accumulator by the

10:39.660 --> 10:46.980
specified operand and stores, the quotient in the accumulator and the remainder in the specified register.

10:46.980 --> 10:48.840
And we have the printf.

10:48.870 --> 10:52.710
This is a function from the C library used for formatted output.

10:52.710 --> 10:57.840
And in the code it's called with arguments stored in registers and displays the formatted message to

10:57.840 --> 10:58.680
the console.
