WEBVTT

00:00.770 --> 00:05.630
Hello, my name is Stephan, and in this video lecture we will delve into the assembly code, which

00:05.630 --> 00:12.380
we will write in calculator, dot, asme file, and this code will demonstrate various arithmetic operations

00:12.380 --> 00:19.760
on numbers using the x86 64 assembly language, and I will also provide comprehensive explanation for

00:19.760 --> 00:26.690
each register and variable used in the code, helping you to understand how the calculations and operations

00:26.690 --> 00:29.130
are carried out step by step.

00:29.150 --> 00:34.580
Now let's open our assembly here and close our previously open terminal.

00:35.240 --> 00:38.930
We will develop it using this and create a new project.

00:39.530 --> 00:41.420
Clear the previous project here.

00:42.490 --> 00:42.690
PM.

00:42.790 --> 00:46.630
I mean the the default code here and here.

00:46.630 --> 00:49.420
We will save it on the assembly.

00:49.420 --> 00:54.160
We will create a new folder, let's name it Calculator.

00:55.780 --> 00:57.710
And calculators.

00:59.470 --> 01:00.190
That's it.

01:01.040 --> 01:04.280
Now, let's name it the calculator.

01:04.310 --> 01:05.900
Calculator.

01:06.290 --> 01:06.590
Dot.

01:07.160 --> 01:12.160
We will declare an external function print f for later use.

01:12.170 --> 01:14.510
So external print f.

01:15.910 --> 01:19.420
Actually decrease the brightness a little bit.

01:19.810 --> 01:20.920
Okay, that's better.

01:20.950 --> 01:23.560
Now what we're going to do is we will section.

01:24.550 --> 01:25.180
Section.

01:25.180 --> 01:26.320
We will cut the section data.

01:26.320 --> 01:26.830
Here.

01:26.830 --> 01:32.740
We will define a 64 bit floating point number with a value of one.

01:33.420 --> 01:34.290
To right.

01:35.040 --> 01:37.380
And number one.

01:40.170 --> 01:43.080
BC for creating floating point numbers.

01:43.080 --> 01:47.070
And we will, uh, give it the value.

01:47.220 --> 01:49.830
One 128.

01:49.860 --> 01:54.030
Number two is going to be, uh, 19 as well.

01:54.030 --> 01:59.640
We will define another 64 bit floating point number with the value of 19.

02:01.660 --> 02:08.770
And we will define a signed 64 bit integer with the value of -12.

02:09.880 --> 02:11.740
Negative number.

02:13.270 --> 02:14.500
So let's make it.

02:15.360 --> 02:19.050
Here, so a negative number DQ as well.

02:19.050 --> 02:19.830
So.

02:28.970 --> 02:29.990
And 12.

02:32.770 --> 02:37.900
And also keep in mind that these are not necessarily floating point numbers.

02:37.900 --> 02:41.950
So you can you can also they can also behave like integers here.

02:42.220 --> 02:46.480
And this is the first number for arithmetic operations.

02:46.480 --> 02:48.790
This is the second number for arithmetic operations.

02:48.790 --> 02:54.130
And this is a negative number to demonstrate sign extension.

02:54.730 --> 02:56.340
And it can also be positive.

02:56.350 --> 03:03.220
We just name it just nick number and we will format the strings for printf function as well.

03:03.220 --> 03:07.450
So we will define fmt DB.

03:12.060 --> 03:16.440
And here the numbers are old.

03:18.040 --> 03:20.080
And here.

03:22.060 --> 03:26.350
Ten zero and we will use fmt int.

03:26.380 --> 03:27.940
I will explain all of this.

03:28.780 --> 03:31.750
After completing this section here.

03:32.890 --> 03:34.240
Like the code section.

03:34.360 --> 03:37.300
I will explain after writing this code.

03:37.420 --> 03:41.290
So s d here again.

03:42.560 --> 03:44.090
And zero.

03:44.800 --> 03:46.090
So me here.

03:47.300 --> 03:49.010
The be here.

03:49.220 --> 03:50.990
The sum is.

03:55.920 --> 03:56.850
And TV.

04:00.330 --> 04:03.660
They pay the difference?

04:06.800 --> 04:08.600
Null terminated strings here.

04:08.690 --> 04:11.600
These are all the null terminated strings.

04:12.840 --> 04:15.270
And I see.

04:15.280 --> 04:15.600
I.

04:18.660 --> 04:19.740
So here.

04:20.480 --> 04:23.960
Number one, incremented.

04:26.790 --> 04:28.230
Null termination.

04:30.410 --> 04:30.950
E.

04:30.950 --> 04:33.440
A c i.

04:35.040 --> 04:35.490
Keep.

04:37.860 --> 04:42.150
Number one incremented here.

04:45.970 --> 04:47.050
Zero as well.

04:48.040 --> 04:49.030
Sally.

04:50.590 --> 04:51.250
EB.

04:53.140 --> 04:55.990
Number one shift.

04:56.620 --> 04:57.280
Left.

04:58.430 --> 05:00.630
Shifts left to here.

05:00.980 --> 05:01.700
X four.

05:08.390 --> 05:09.500
Zero again.

05:10.490 --> 05:12.450
S s a r.

05:13.650 --> 05:14.610
A here.

05:18.310 --> 05:21.970
Number one shift, right?

05:24.480 --> 05:26.250
Right to.

05:27.220 --> 05:30.790
Which is divide by 2 or 4.

05:36.610 --> 05:42.790
Zero and s a r i.

05:43.120 --> 05:43.870
X.

05:47.220 --> 05:48.660
Number one.

05:49.900 --> 05:51.550
Shift, right?

05:52.390 --> 05:57.580
But this one will be shifted with the sign expression.

05:59.920 --> 06:01.540
Us with.

06:03.350 --> 06:05.660
So in the expression here.

06:12.020 --> 06:13.730
Let's add a termination.

06:15.080 --> 06:15.880
Add multi.

06:15.890 --> 06:22.100
We just need to write three lines of code and after that I will explain registers and everything here.

06:23.550 --> 06:24.270
Here.

06:24.360 --> 06:24.870
TB.

06:26.130 --> 06:28.440
This is the the product.

06:35.580 --> 06:41.910
And here this is the integer coefficient.

06:47.140 --> 06:48.610
The integer.

06:50.320 --> 06:51.970
And as.

06:55.530 --> 06:58.800
And lastly, we have the Remy here.

07:00.640 --> 07:04.030
The be here the modulo.

07:05.620 --> 07:06.430
Is.

07:08.320 --> 07:08.790
Zero.

07:08.800 --> 07:12.280
Now that's it with our code for now.

07:12.280 --> 07:16.180
Here we will add also, we will also add more codes here.

07:16.540 --> 07:19.140
Here we just developed a section data here.

07:19.150 --> 07:28.990
Now the the registers, um, like the general purpose registers are used to hold data and perform arithmetic

07:28.990 --> 07:31.870
operation, which we will learn that in next lecture.

07:31.870 --> 07:39.400
But firstly, what we're going to sing here is at the second line of our program here we are declaring

07:39.400 --> 07:48.190
an external function printf that is used in another module like C library, and this allows the assembly

07:48.190 --> 07:52.750
code to call the printf function for output.

07:52.750 --> 07:58.660
And in this data here we are declaring a section of memory where initialized data is stored.

07:58.690 --> 08:06.430
The number one, number two and the negative number are initialized with a specific values for arithmetic

08:06.430 --> 08:07.360
operations.

08:08.160 --> 08:08.940
And.

08:10.050 --> 08:12.210
And we also have the format strings here.

08:14.430 --> 08:21.920
And here the first format string does that here, this fmt here.

08:21.930 --> 08:28.480
So this format string is used to display the values of two long integers.

08:28.500 --> 08:32.270
The LD and the LD here, as you can see.

08:32.280 --> 08:39.570
So LD is a placeholder that will be placed with the actual values of the long integers.

08:40.560 --> 08:49.020
And ten here represents the Ascii code for a new line character like the new line character.

08:49.020 --> 08:49.980
This here.

08:50.880 --> 08:57.990
And after that, so we have the new line and this is the zero indicates the end of the string, which

08:57.990 --> 09:03.090
is a null terminated string here to mark its completion.

09:05.130 --> 09:09.660
And also we have here is let me actually fix this mask.

09:10.050 --> 09:14.790
Also, we have here the fmt, uh, integer here.

09:16.800 --> 09:23.010
So the this form of string is used to display a string followed by a long integer.

09:23.010 --> 09:25.020
As you can see here, this is a string.

09:25.020 --> 09:29.610
This is a long integer and the S is a placeholder for a string.

09:29.610 --> 09:33.450
And the L is a placeholder for a long integer.

09:33.450 --> 09:38.120
And ten here represents the Ascii code for a new line character as well.

09:38.130 --> 09:42.000
The this is the new line character and.

09:43.100 --> 09:47.330
This will cause the new line to be printed after this value.

09:47.690 --> 09:51.200
And this zero here indicates the end of a string.

09:51.470 --> 09:54.440
It's also called the null terminated string.

09:54.440 --> 09:58.220
And we also have the Sumi here as.

09:58.990 --> 10:00.700
You, am I?

10:01.150 --> 10:07.600
So this format string is a message to be printed before displaying the sum of two numbers.

10:07.720 --> 10:14.650
The string simply states the sum is and zero here indicates the end of the string, which is a null

10:14.650 --> 10:15.540
terminated string.

10:15.550 --> 10:22.870
And we also have d here d i f i.

10:23.440 --> 10:24.520
Similar to the previous one.

10:24.520 --> 10:29.680
The this format string is a message to be printed before displaying the difference.

10:30.130 --> 10:33.030
Uh, with the difference of two numbers.

10:33.040 --> 10:39.040
The string states, the the differences and zero indicates the end of the string.

10:39.070 --> 10:42.550
And also we have a i n c i.

10:42.790 --> 10:49.240
This is the format string message is to be printed before displaying the increment value of the first

10:49.240 --> 10:49.450
one.

10:49.450 --> 10:55.630
The string just simply states number one incremented and zero indicates the end of the string.

10:55.660 --> 10:56.710
So.

10:57.990 --> 11:00.390
We have the same here.

11:00.390 --> 11:02.430
And that's it.

11:03.330 --> 11:06.300
And yeah, that they are basically the same here.

11:06.300 --> 11:10.920
They are just a string we are attaching to this variable names and so on.

11:10.920 --> 11:17.250
So this format strings are essential for presenting clear and informative output messages when performing

11:17.250 --> 11:24.000
arithmetic operations and manipulations on the provided numbers so the placeholders within the format

11:24.000 --> 11:29.160
string will be replaced with the actual values like these placeholders.

11:29.160 --> 11:31.260
Here's LD and so on.

11:32.970 --> 11:39.960
Uh, so they will they will be replaced with the actual values during the printf function called the

11:39.960 --> 11:49.110
null termination at the end of every string here is crucial for proper string handling in C and other

11:49.110 --> 11:52.290
low level languages, like in assembly language as well.

11:52.290 --> 12:00.900
So this code essentially sets, but actually so you don't add the null terminated string characters

12:01.470 --> 12:04.530
manually just handles it automatically.

12:05.750 --> 12:13.160
Now, this code here essentially sets sets up data values for my strings and external function declarations

12:13.160 --> 12:18.710
for performing arithmetic operations on the provided numbers and demonstrating various manipulations.

12:18.710 --> 12:25.610
So the format strings are used with the printf function to display the messages and computed results.

12:25.820 --> 12:33.650
So the x86 64 assembly registers are key elements in executing the arithmetic, operations and manipulations

12:33.650 --> 12:36.320
outlined in this code.

12:36.650 --> 12:39.920
I'm awaiting you in next lecture for continuing our project.
