WEBVTT

00:00.470 --> 00:01.580
Hello, my name is Stefan.

00:01.580 --> 00:07.780
And in this lecture we are going to develop our project calculator project further here.

00:07.790 --> 00:14.270
Now, as I always do, we will I will explain the code while I'm writing it.

00:14.270 --> 00:17.570
And also, uh, when I'm done.

00:17.570 --> 00:27.290
So now we will need to develop our BBS section here, uh, which we will just uh, define two variables.

00:27.290 --> 00:35.720
So section BBS, result result I rescue here.

00:35.720 --> 00:42.860
One result or modulo here is rescue one as well.

00:43.040 --> 00:49.520
And here we will define text section where we will our code will be written.

00:49.520 --> 00:54.710
We will define global main define the main function.

00:54.890 --> 00:59.300
We will here write push RVP move.

01:01.540 --> 01:03.640
RWP rsp.

01:03.670 --> 01:04.930
You already know what that means.

01:04.930 --> 01:06.130
But I will also.

01:06.340 --> 01:08.080
I will explain it again.

01:08.500 --> 01:17.290
And what we're going to do is we will display the numbers here and we will write five instructions,

01:17.290 --> 01:20.830
move the i fmt.

01:22.340 --> 01:24.110
We need this tabs.

01:24.990 --> 01:30.300
So basically we are loading the address of format string to RDR.

01:30.330 --> 01:33.180
Remember this format string is the number here.

01:34.420 --> 01:37.090
Fmt move here.

01:37.480 --> 01:38.290
RSI.

01:40.100 --> 01:42.350
This is number one.

01:42.380 --> 01:49.510
This is the this is for loading the value of number one into RSI.

01:50.670 --> 01:50.850
Here.

01:50.880 --> 01:56.190
Number one is 128 and number two is 19.

01:57.520 --> 02:01.450
And here we will do the same for number.

02:03.230 --> 02:03.950
To.

02:03.980 --> 02:05.360
So move.

02:06.380 --> 02:07.640
Are the eggs.

02:10.280 --> 02:14.390
Number two and move.

02:15.250 --> 02:16.000
Racks.

02:20.410 --> 02:21.040
Zero.

02:21.610 --> 02:26.170
And after that we will call a printf to display the formatted message call.

02:26.290 --> 02:27.370
Printf.

02:28.570 --> 02:32.470
And after that we will need to write the adding here.

02:33.250 --> 02:36.280
So move racks.

02:40.220 --> 02:41.310
Number of.

02:44.400 --> 02:45.510
Number one.

02:47.590 --> 02:48.190
At.

02:48.920 --> 02:49.820
Racks.

02:51.710 --> 02:52.910
Number two.

02:54.040 --> 03:00.100
Here in this here we are loading the value of number one into racks and.

03:01.380 --> 03:06.360
We are doing the same for adding the value of number two to racks.

03:06.360 --> 03:14.250
But here we are loading and here in this here we are adding here, which you will see the difference

03:14.250 --> 03:16.710
right now and result.

03:16.740 --> 03:24.090
We will store the result in this result I reserve so.

03:26.640 --> 03:27.270
Result.

03:27.310 --> 03:28.950
I hear.

03:30.290 --> 03:31.040
Tracks.

03:33.980 --> 03:36.380
And after that, we need to.

03:37.910 --> 03:40.610
We need to display the result as well again.

03:41.180 --> 03:44.880
So display the result.

03:44.900 --> 03:46.220
So move.

03:46.260 --> 03:47.000
Ready?

03:48.940 --> 03:54.790
Fmt fmt integer, which we define somewhere here.

03:57.510 --> 03:57.870
So.

03:59.910 --> 04:01.200
Empty end.

04:02.220 --> 04:08.220
Now what we're going to what we are doing here is we are loading and loading the address of format string

04:08.250 --> 04:12.120
to RTI and MOV RSI.

04:13.390 --> 04:13.960
Some.

04:14.890 --> 04:15.940
Am I here?

04:16.150 --> 04:16.840
This is the.

04:16.840 --> 04:19.660
This is for loading the address of message to RSI.

04:20.200 --> 04:22.690
MOV rdx.

04:26.540 --> 04:29.060
And with this we will.

04:31.410 --> 04:32.250
Actually, yeah.

04:32.760 --> 04:42.540
Uh, uh, with RDX, we will need to load the value of result I result here uh, two, which is.

04:43.110 --> 04:45.450
Or we define it as a reserve.

04:47.130 --> 04:48.420
Who are the.

04:52.720 --> 04:54.130
And after that move.

04:55.060 --> 04:56.100
RDX.

04:57.420 --> 04:58.900
Or racks.

04:58.920 --> 04:59.700
Racks.

05:01.170 --> 05:01.770
Zero.

05:01.800 --> 05:08.490
With this, we are clearing the racks register, which is basically returning the value and after that

05:08.490 --> 05:11.030
we will call them printf.

05:12.200 --> 05:14.900
Which is calling primitive to display the formatted message.

05:21.530 --> 05:22.030
Printf?

05:22.340 --> 05:23.000
Yeah.

05:23.360 --> 05:28.490
And after that, we will need to create our subtracting here.

05:28.820 --> 05:33.220
And after that I will begin to explain these codes.

05:33.230 --> 05:33.710
So.

05:39.580 --> 05:44.560
Acting and move racks.

05:48.170 --> 05:49.240
Number one.

05:49.250 --> 05:53.810
Here we are loading the value of number one into racks sub.

05:55.500 --> 05:56.220
Racks.

05:58.800 --> 06:00.180
Number two.

06:01.470 --> 06:02.160
Move.

06:05.510 --> 06:06.830
Of result.

06:10.270 --> 06:10.860
Rags.

06:10.930 --> 06:12.460
Here we are, storing the value.

06:12.490 --> 06:15.320
Storing the result in a result.

06:15.340 --> 06:16.320
Result I.

06:16.330 --> 06:17.410
And here we are.

06:17.410 --> 06:18.060
Subtracting.

06:18.160 --> 06:22.270
Subtracting the value of number two from rags.

06:23.020 --> 06:27.700
And now we will need to display the result.

06:27.910 --> 06:30.820
Displaying the result.

06:32.240 --> 06:33.650
And here.

06:34.980 --> 06:35.220
That's.

06:36.590 --> 06:42.860
So here what we're going to do is we will load the address of, uh, format string to RTI.

06:43.700 --> 06:44.900
RTI.

06:49.640 --> 06:53.960
And FM to integer move.

06:54.700 --> 06:55.770
RSI.

06:57.820 --> 07:00.730
If you are here we are loading address of message to RSI.

07:01.240 --> 07:02.080
Move.

07:02.910 --> 07:03.450
Are the.

07:04.880 --> 07:07.400
This is fall result I.

07:09.240 --> 07:18.240
They are loading the value of result I to RDX and now we will move our r r a x.

07:18.600 --> 07:25.140
Here we are clearing the x register, returning the value again, and we will call the print.

07:25.590 --> 07:27.360
Our code is not yet done.

07:27.360 --> 07:31.560
We need to add another mathematical arithmetics as well.

07:31.560 --> 07:35.100
But here for this lecture, I will explain this.

07:35.130 --> 07:38.400
So, uh, here.

07:39.990 --> 07:44.520
At first you remember we had this push and move.

07:44.520 --> 07:45.480
RWP rsp.

07:46.650 --> 07:49.230
But we will start from here firstly.

07:49.230 --> 07:57.210
So with this here move ah, the I fmt we are moving the memory address of the format string fmt into

07:57.210 --> 08:02.940
RDA register and RDA will be used as the first argument for this printf function.

08:02.940 --> 08:08.400
And here we are moving the.

08:09.550 --> 08:15.640
Value stored at the memory location pointed to by number one into the RSI register.

08:15.640 --> 08:20.740
And this loads the value of the first number for displaying.

08:20.770 --> 08:27.850
And here we are moving the value stored at the memory location pointed to by number two into the RDX

08:27.880 --> 08:32.770
register, and this loads the value of second number for displaying as well.

08:32.770 --> 08:35.800
And here we are calling the um.

08:38.720 --> 08:40.820
And here we are calling the.

08:42.370 --> 08:50.470
Printf, which calls the string function to display the formatted message using the provided, um,

08:50.470 --> 08:57.070
argument like RTI, RSI and RDX here.

08:59.200 --> 09:02.750
And after that we have moved racks number one.

09:02.770 --> 09:04.180
This is for moved moves.

09:04.180 --> 09:09.580
The value stored at the memory location pointed to by number one into the racks register.

09:09.580 --> 09:10.740
And this.

09:10.750 --> 09:14.290
This loads the value of the first number for arithmetic operations.

09:14.290 --> 09:17.560
And here we are with this.

09:19.040 --> 09:20.130
Here we are telling.

09:20.180 --> 09:26.720
Telling the assembler to add the value stored at the memory location pointed to by number two to the

09:26.720 --> 09:28.340
value in Rax register.

09:28.340 --> 09:34.160
So this result the result is stored in Rax representing the sum of two numbers.

09:34.220 --> 09:39.680
And here we are storing the value in the rax register which is sum of the numbers.

09:40.070 --> 09:41.840
Sum of the numbers.

09:42.170 --> 09:49.960
Summary of the numbers into the memory location pointed to by result I here and we are.

09:51.360 --> 09:53.040
In display here.

09:53.070 --> 10:02.790
I move Fmt and RDL will be used as the first argument for the printf function and here RSI will be used

10:02.790 --> 10:05.580
as the second argument for the printf function here.

10:05.580 --> 10:07.800
And this loads the.

10:08.370 --> 10:14.040
This loads the result of the addition operation for displaying.

10:14.790 --> 10:22.200
So this clears the rax register, preparing it to be used as the return value for the printf function.

10:22.350 --> 10:28.950
And here we are calling the printf function to display the formatted message using the provided arguments,

10:28.950 --> 10:32.040
which is RDA, RSI and RDX.

10:32.040 --> 10:39.660
So this subsequent subtracting section follows a similar pattern with the sub instruction to subtract

10:39.660 --> 10:45.540
the second number from the first number and the same process for displaying the difference.

10:45.540 --> 10:46.830
And please.

10:50.770 --> 10:51.220
Here.

10:51.220 --> 10:57.280
Keep in mind that this printf is callable function from an external library.

10:58.270 --> 10:59.020
And.

11:00.110 --> 11:04.040
As you can see here, it's being used for output purposes.

11:05.170 --> 11:14.050
And as you can see here, we almost all fully completed we completed 50% of our program, which we will

11:14.050 --> 11:19.390
continue that in our lecture in in our next next lecture.
