WEBVTT

00:00.320 --> 00:04.850
Hello, my name is Stephan, and in this lecture we will develop another assembly program.

00:04.850 --> 00:12.470
And now that you have a firm grasp of GDB and know what an assembly program looks like, let's add some

00:12.470 --> 00:13.430
complexity.

00:13.460 --> 00:18.920
In this lecture I will show you how to obtain the length of a string variable.

00:19.100 --> 00:26.300
I will show you how to print integer and floating point values using printf and I will expand your knowledge

00:26.300 --> 00:28.210
of GDB commands.

00:28.220 --> 00:36.530
So now here we will firstly open CSM or you can also choose another text editor so you don't need much

00:36.530 --> 00:39.410
about creating or developing assembly code.

00:39.620 --> 00:43.070
And let's actually use the CSM here.

00:43.070 --> 00:44.720
Now create a new project here.

00:44.720 --> 00:47.270
Let's delete this project, save it somewhere.

00:47.270 --> 00:51.170
In this case, let's actually our project name is going to be kicking.

00:52.340 --> 00:52.910
That's it.

00:52.940 --> 00:57.500
Now save it as the name of kicking that --.

00:57.950 --> 00:58.580
That's it.

00:58.580 --> 01:00.740
And here is our code.

01:00.770 --> 01:03.860
Now we will firstly comment it out.

01:03.860 --> 01:05.840
Our the.

01:07.350 --> 01:11.400
Assembly program, name, file name, RSM here.

01:11.430 --> 01:18.810
Now we will firstly add this data section in it here because we will add the two variables.

01:18.810 --> 01:21.510
It's actually two variables, but we will add four variables.

01:21.510 --> 01:27.270
The two variables is for the our string and string.

01:27.300 --> 01:33.810
And the second variables is the length of the first string and the length of the second string.

01:33.810 --> 01:43.260
Now here we will firstly write this the message MSG one db here.

01:43.650 --> 01:44.850
Hello world.

01:45.000 --> 01:48.240
Let's actually case sensitive words here.

01:48.390 --> 01:51.930
Hello world and ten zero.

01:52.900 --> 01:54.950
And a comma and zero here.

01:54.970 --> 01:56.560
So what?

01:56.800 --> 01:58.540
So this is something new, right?

01:58.540 --> 02:00.790
So we added zero for the null terminated.

02:01.240 --> 02:04.990
But here we added ten, which I will explain right now.

02:04.990 --> 02:10.390
So this is the string with an L and zero.

02:12.000 --> 02:15.060
The string width and zero here.

02:15.690 --> 02:17.340
We will also have the.

02:19.000 --> 02:20.240
Message one.

02:20.260 --> 02:21.670
Length here.

02:21.790 --> 02:23.170
Actually, length is okay.

02:23.170 --> 02:32.380
So we will write here and what we're going to do, we will take this message variable minus message

02:32.380 --> 02:33.670
one, minus one.

02:33.670 --> 02:38.770
So this is for measuring the length minus the zero here.

02:38.770 --> 02:40.450
So measure.

02:41.550 --> 02:43.320
Measure the length.

02:44.200 --> 02:49.240
Of message one and minus.

02:50.030 --> 02:50.810
The zero.

02:51.020 --> 02:54.560
And we will also create our string too.

02:55.490 --> 02:58.400
We will name it MSG two.

02:58.460 --> 03:02.750
Here we will write it DB right here.

03:02.750 --> 03:09.530
And our message is going to be kicking and alive this here.

03:09.740 --> 03:10.610
So.

03:12.130 --> 03:12.430
Here.

03:12.430 --> 03:13.390
We will also.

03:15.270 --> 03:17.750
All this again, ten and zero.

03:17.750 --> 03:23.540
Remember, this ten is for new line and is for nation.

03:24.200 --> 03:26.920
So we will terminate our string after new line.

03:26.930 --> 03:27.320
Right.

03:27.320 --> 03:32.840
So string with L and zero here.

03:35.720 --> 03:39.680
And after that, we will also create the search tool.

03:39.680 --> 03:40.610
Len, here.

03:40.640 --> 03:43.610
This is going to be, again, equal here.

03:43.700 --> 03:48.590
And here we will again measure the length and we will miss the zero.

03:48.770 --> 03:51.740
So a message to.

03:52.710 --> 03:54.720
Minus one here.

03:55.740 --> 03:58.560
So this is for the measure.

03:59.450 --> 04:03.110
The length of message to.

04:04.980 --> 04:06.300
Plus minus.

04:08.070 --> 04:08.970
The zero.

04:10.260 --> 04:13.770
And here we will create some radius.

04:13.770 --> 04:15.510
So this is the radius.

04:15.510 --> 04:21.870
And pi is actually the terminology for you, which you will learn by the end of this section.

04:21.990 --> 04:25.990
I will explain this terminologies deeply later.

04:26.010 --> 04:27.540
So radius.

04:28.340 --> 04:31.790
Be cool not to be here and.

04:31.790 --> 04:34.550
357.

04:35.410 --> 04:37.300
And we will add comments.

04:37.300 --> 04:41.080
But as I say, they I will explain this further.

04:41.380 --> 04:42.700
String not.

04:44.080 --> 04:44.530
This.

04:45.600 --> 04:46.830
Is playable.

04:49.200 --> 04:49.470
Again.

04:49.470 --> 04:51.090
We will copy this.

04:55.540 --> 04:57.730
And we will again create a P here.

04:57.760 --> 04:58.270
P.

04:59.640 --> 05:03.270
BQ 3.14 and again.

05:10.180 --> 05:12.850
So now our section data is completed.

05:12.850 --> 05:17.620
Now we will also create the section which we will not use.

05:17.950 --> 05:20.050
We will not notice anything here.

05:20.200 --> 05:29.050
Section The main where our main function will live here is section text and we will create a global

05:29.080 --> 05:29.890
main.

05:30.620 --> 05:34.970
Now let's start developing our main function.

05:34.970 --> 05:40.220
So in our main function we will again add the we will push the.

05:41.170 --> 05:42.510
R p.

05:42.520 --> 05:43.330
P.

05:44.240 --> 05:47.150
This is the function prologue.

05:47.190 --> 05:48.170
Actually, we can.

05:50.770 --> 05:53.500
Less taps, though, because we will not have.

05:55.820 --> 05:56.750
The strings here.

05:57.620 --> 05:59.360
These are just instructions.

05:59.480 --> 06:01.670
So here, this is the.

06:03.610 --> 06:05.860
Function prologue.

06:08.680 --> 06:09.190
Move.

06:11.180 --> 06:13.520
Are BP RSP.

06:13.550 --> 06:16.580
This is, again a function prologue as well.

06:19.140 --> 06:19.950
Move.

06:22.760 --> 06:23.360
One.

06:25.510 --> 06:27.070
I always add this here.

06:39.600 --> 06:40.020
Here.

06:40.020 --> 06:45.510
So Rex1 is as we did in previous lectures.

06:45.510 --> 06:48.060
This is for right writing here.

06:48.450 --> 06:50.100
One is right.

06:50.700 --> 06:53.070
And we will again move here.

06:53.430 --> 06:54.170
Ready?

06:55.340 --> 06:59.960
As for to write on the console.

07:04.080 --> 07:05.970
To STD out.

07:06.990 --> 07:07.190
Out.

07:07.200 --> 07:07.650
Out here.

07:07.650 --> 07:08.700
So move.

07:09.880 --> 07:11.080
RSI.

07:12.520 --> 07:13.420
Message one.

07:13.420 --> 07:14.740
First, we will use this message.

07:14.740 --> 07:15.240
One.

07:15.250 --> 07:16.300
So this is the.

07:19.730 --> 07:23.660
String to display and after that.

07:25.510 --> 07:26.490
We will again.

07:26.500 --> 07:27.520
We will move.

07:30.720 --> 07:32.310
Are the eggs.

07:32.550 --> 07:39.870
And after that we will again print the length of this message one string, and after that we will apply

07:39.870 --> 07:42.480
the same for the message to here.

07:42.750 --> 07:44.820
Message one length.

07:44.850 --> 07:45.540
Here.

07:47.690 --> 07:49.100
This is the length.

07:50.820 --> 07:53.070
Of the string here.

07:53.070 --> 07:56.160
Actually, we let's actually add tabs.

07:57.180 --> 07:58.410
More tabs here.

07:59.640 --> 08:02.370
Doesn't look good here for display purposes.

08:03.550 --> 08:04.960
And that's it.

08:04.970 --> 08:09.260
After that, we will call the syscall to display the string.

08:09.280 --> 08:10.960
Display the string.

08:10.960 --> 08:12.760
So these are the comments, as you know.

08:14.280 --> 08:17.010
So we will again instead of writing.

08:17.040 --> 08:19.830
Actually we can write it out here.

08:19.830 --> 08:24.180
So rax one, it's for one.

08:25.010 --> 08:25.940
Right.

08:26.930 --> 08:28.300
Of I.

08:30.240 --> 08:35.940
Are thy one is for the STD out.

08:39.470 --> 08:41.120
STD out.

08:43.190 --> 08:44.390
And after that.

08:45.030 --> 08:45.600
It's called.

08:48.860 --> 08:54.430
Tracks RDA and after that we will need to add RSA again.

08:54.560 --> 08:55.880
Message to.

08:56.950 --> 09:02.620
Um, this is the string to display and move again.

09:02.650 --> 09:04.420
Ah, the X.

09:04.840 --> 09:07.870
This is the message to Len.

09:08.590 --> 09:11.980
And again, this is the length of the string.

09:12.220 --> 09:15.610
Length of the string.

09:19.380 --> 09:20.520
Length out a string.

09:21.240 --> 09:21.960
And.

09:24.580 --> 09:25.420
After that.

09:25.420 --> 09:26.190
That's it.

09:26.200 --> 09:26.890
We will.

09:28.530 --> 09:29.960
You can call the syscall.

09:31.790 --> 09:33.500
So this is for.

09:34.710 --> 09:40.870
Displaying this string again, the second string which is kicking in the live display.

09:40.890 --> 09:48.000
So you might be wondering where we will use this radius and pi here, which we will use that right now.

09:51.110 --> 09:54.350
And this is the skull is display.

09:55.430 --> 09:57.290
The ring.

09:58.770 --> 10:03.690
And after that, this is the last year, so we will develop the function.

10:03.690 --> 10:04.470
Epilogue.

10:04.620 --> 10:05.100
Function.

10:05.100 --> 10:05.590
Epilogue.

10:05.610 --> 10:09.300
Again, we will add exit and success exit code again.

10:09.300 --> 10:13.980
And after that we will again call the syscall to quit the program.

10:13.980 --> 10:14.490
Right.

10:14.490 --> 10:15.300
So.

10:16.360 --> 10:20.880
After calling the Siskel here again, we will call it one more time.

10:20.890 --> 10:28.150
After completing these four lines of code, we will firstly create a two function epilogue Our BP.

10:29.840 --> 10:31.760
Are here.

10:32.480 --> 10:33.320
Cases here.

10:37.990 --> 10:38.910
Bob, I.

10:38.950 --> 10:39.370
Okay.

10:39.370 --> 10:40.630
You can't hear my voice.

10:40.990 --> 10:41.370
Okay.

10:41.630 --> 10:42.130
Beep.

10:42.730 --> 10:43.540
I just scared.

10:43.540 --> 10:47.530
I thought this ten minutes of work just for nothing.

10:48.530 --> 10:50.030
And here are BP.

10:50.540 --> 10:53.360
This is the function epilogue.

10:54.700 --> 10:56.850
And again move RB.

10:58.200 --> 11:02.550
Here are BP again without the BP.

11:02.580 --> 11:03.780
Here just BP.

11:05.030 --> 11:08.680
This is the function epilogue as well.

11:08.690 --> 11:14.450
And after that we will move the racks which we did in previous code here.

11:14.450 --> 11:20.360
This is for the 60 means exit, and after that we will again call.

11:20.360 --> 11:31.210
Lastly, rest instruction is called RDA and this is for the zero, which is the success exit code as.

11:32.040 --> 11:34.200
Exit code and after that.

11:36.170 --> 11:37.130
Port here.

11:37.130 --> 11:40.140
And after that we will call the syscall.

11:40.160 --> 11:41.660
And that's.

11:42.490 --> 11:43.540
Uh, quit.

11:43.750 --> 11:44.500
This is just a quick.

11:44.500 --> 11:45.930
So our program is done.

11:45.940 --> 11:54.550
So this type of programming to your, uh, you can write it in your, um, favorite editor and save

11:54.580 --> 11:56.260
as kicking the ACM.

11:56.260 --> 12:01.090
And now in next lecture, we will create the make file here.

12:01.090 --> 12:03.250
So I'm waiting you in next lecture.
