WEBVTT

00:00.590 --> 00:01.730
Hello, my name is Typhoon.

00:01.730 --> 00:06.500
And in this lecture we will delve into the fascinating world of assembly language programming.

00:06.530 --> 00:11.930
In this lecture, we will explore the intricacies of some fundamental arithmetic operations within our

00:11.930 --> 00:12.680
program.

00:13.330 --> 00:22.090
Now get ready to witness the magic of incrementing decrementing shifting, multiplying and dividing.

00:22.120 --> 00:29.200
And throughout this lecture, we will dissect each of these operations step by step, unraveling the

00:29.200 --> 00:34.110
code line by line to understand how they work at their core.

00:34.120 --> 00:41.200
And we will be working with registers, memory and functions to manipulate numbers and display their

00:41.200 --> 00:42.010
results.

00:42.040 --> 00:48.400
The assembly language offers us a such a unique perspective into the inner workings of computers, low

00:48.400 --> 00:56.110
level operations, providing insights into how calculations are executed at the hardware level.

00:56.140 --> 01:02.950
Starting with incrementing, we will see how a single instruction can add one to a number and transform

01:02.950 --> 01:04.220
its value from there.

01:04.240 --> 01:12.190
We will move to Decrementing where we will learn how subtraction plays a role in reducing values.

01:12.950 --> 01:13.550
Shifting.

01:13.550 --> 01:19.970
Our next venture allows us to multiply and divide by powers of two throughout bit manipulation.

01:20.600 --> 01:26.930
And this demonstrates how computer architects use clever tricks to optimize certain operations.

01:26.930 --> 01:30.800
And our journey continues with multiplication and division.

01:30.800 --> 01:36.800
By diving into these operations, we will understand how computers perform these fundamental arithmetic

01:36.830 --> 01:42.620
tasks and how we can harness their power in assembler language.

01:42.620 --> 01:47.510
So fasten your belts as we embark on this enriching journey.

01:47.510 --> 01:54.710
But also by the end of this lecture you will have a solid grasp grasp of incrementing decrementing shifting,

01:54.710 --> 01:58.940
multiplying and dividing, working in assembly language.

01:59.210 --> 02:05.570
Now let's dive in to explore the intricate dance between software and hardware that makes these operations

02:05.570 --> 02:06.380
possible.

02:06.380 --> 02:14.060
But first we will write the incrementing incrementing side of our program.

02:14.060 --> 02:18.140
Here we will load the value of number one to rax.

02:18.140 --> 02:19.370
So move.

02:20.110 --> 02:21.410
Move rax.

02:23.600 --> 02:26.960
Uh, number one inside braces.

02:26.990 --> 02:31.660
Now we will use I and C racks.

02:32.220 --> 02:36.630
This we use this for incrementing rex by one.

02:36.650 --> 02:40.220
We will store the result in result I.

02:40.950 --> 02:41.640
Move.

02:42.980 --> 02:44.750
The result, I result.

02:46.660 --> 02:48.100
And racks.

02:48.490 --> 02:50.620
We will display the result here.

02:50.620 --> 02:53.050
So display the result.

02:54.690 --> 02:56.940
And after that we will move the.

02:58.670 --> 02:59.900
Fmt int.

02:59.930 --> 03:03.260
This is for a local address of format.

03:03.290 --> 03:10.040
Uh, we are loading the address of format string to die and now we will load the address of message

03:10.040 --> 03:10.880
to RSI.

03:11.240 --> 03:14.600
RSI The address of messages.

03:16.760 --> 03:19.130
I nci here.

03:19.160 --> 03:19.910
Number one.

03:20.120 --> 03:21.950
Number one, incremented.

03:23.160 --> 03:23.460
I.

03:24.630 --> 03:25.580
Move.

03:26.280 --> 03:27.140
Move!

03:27.150 --> 03:28.980
RDX.

03:29.940 --> 03:30.990
Result, I.

03:31.020 --> 03:35.970
Here we are loading the value of result i to RDX.

03:36.000 --> 03:40.290
Now we will clear the rax register which is returning the value.

03:41.050 --> 03:46.000
And now we will call the printf to display the formatted message.

03:46.030 --> 03:50.470
Now we will develop the decrementing here.

03:50.470 --> 03:55.240
So we will move load the value of number one to rax.

03:57.210 --> 03:57.990
Move.

04:02.910 --> 04:03.780
Racks.

04:04.730 --> 04:07.040
The number one.

04:08.070 --> 04:19.110
Uh, these here we in incrementing we use I and C and here we will use the c here rax this is for decrementing

04:19.110 --> 04:20.730
rax by one.

04:20.820 --> 04:30.060
We will use move here result i here rax we are storing the result in result i and now we will need to

04:30.060 --> 04:31.470
display the results.

04:31.470 --> 04:34.620
So display the result.

04:34.680 --> 04:43.620
Now we will use the load load address of format string to move the i fmt int.

04:45.830 --> 04:46.100
Right?

04:46.110 --> 04:46.730
Yeah.

04:47.090 --> 04:49.760
Fmt it mov rsi.

04:50.990 --> 04:52.850
Uh, Daisy here.

04:54.100 --> 04:55.780
There are string.

04:56.570 --> 04:57.500
Start.

04:58.860 --> 04:59.430
Let's see.

05:02.230 --> 05:02.530
E.

05:02.530 --> 05:03.040
A.

05:03.040 --> 05:03.880
S.

05:03.880 --> 05:06.070
C, d, a c.

05:06.460 --> 05:08.350
And now.

05:09.620 --> 05:12.890
We will use load the value of result I to RDX.

05:12.890 --> 05:15.260
Move RDX.

05:16.190 --> 05:28.050
Result I here and now we will move the racks zero to clear the racks register and we will call the printf.

05:28.730 --> 05:30.590
And now we will need to shift.

05:30.770 --> 05:33.530
Use the shift arithmetic left here.

05:33.830 --> 05:34.820
Shift.

05:35.240 --> 05:39.530
Left shift our metric.

05:42.050 --> 05:42.560
Are.

05:45.240 --> 05:47.190
Arithmetic left.

05:48.000 --> 05:53.010
So here what we're going to do is we will load the value of number one to Rax.

05:53.010 --> 06:00.030
So move rax number one cell rax.

06:00.910 --> 06:01.480
Two.

06:01.510 --> 06:04.300
I will explain all of this newly.

06:07.510 --> 06:08.020
Here.

06:08.020 --> 06:09.280
So move.

06:10.050 --> 06:21.480
Result I here and Rex here we shift Rex left by shifting the Rex left by two bits, which is me, which

06:21.480 --> 06:23.760
means multiplying by four.

06:23.790 --> 06:35.070
Here we are storing the result in result I here and now we will need to display display the result.

06:35.100 --> 06:36.090
Now we are.

06:36.240 --> 06:36.510
We are.

06:36.660 --> 06:40.640
We need to load the address of format string to r.d.e.

06:40.680 --> 06:42.060
So move the.

06:42.980 --> 06:46.820
Are the I fmt integer.

06:48.390 --> 06:50.160
Move the RSI.

06:54.540 --> 06:58.290
Sally, which we defined previously in data section.

07:00.570 --> 07:04.740
Number one shift left to which is multiplying by four.

07:05.590 --> 07:18.730
And move RDX here, which is, uh, for loading the value of result result i to RDX result I to RDX.

07:18.760 --> 07:25.420
Now we will move the racks so we will clear the racks register which is returning the value and we will

07:25.420 --> 07:28.000
lastly call the printf.

07:28.030 --> 07:29.140
Printf.

07:30.100 --> 07:33.060
And after that we will need to shift arithmetic.

07:33.070 --> 07:37.030
We will we will need to write shift arithmetic right here.

07:37.300 --> 07:39.580
So shift.

07:40.920 --> 07:43.770
Arithmetic right now.

07:43.770 --> 07:44.070
We will.

07:44.070 --> 07:44.520
Right.

07:44.550 --> 07:45.360
Move.

07:47.710 --> 07:48.310
Move.

07:49.900 --> 07:59.860
Tracks, number one, which is for loading, not bomber number one, and this is for loading the value

07:59.860 --> 08:02.140
of number one to racks.

08:02.140 --> 08:11.410
So s a R for shifting racks right by two bits, which is arithmetic shift, which is this.

08:11.410 --> 08:24.160
This here is divided by four here shift of SA racks and two and move.

08:25.920 --> 08:31.560
Result I here registered result in a result I now display.

08:31.590 --> 08:33.720
Display the result.

08:34.020 --> 08:34.890
Move.

08:35.880 --> 08:44.400
RTI Fmt which is load which is assembly code here loads the address of format string to RTI.

08:45.970 --> 08:50.980
MOV rsi sa i here.

08:51.010 --> 08:54.280
This is followed the address of message to RSI.

08:54.700 --> 09:05.050
Now we will load the value of result I to RDX, move the RDX to result I here and now we will move the

09:05.050 --> 09:14.920
rax we will clear the rax basically call printf again print f they're calling printf to display the

09:14.920 --> 09:16.210
formatted message.

09:16.210 --> 09:19.930
We just need to now write the shift arithmetic.

09:19.930 --> 09:21.610
Right with sign expression.

09:21.880 --> 09:26.410
Uh, and as well we will write displaying the result as well.

09:26.410 --> 09:31.330
And we will write, multiply, divide and we will end the program.

09:31.330 --> 09:34.600
And then in next lecture we will try to analyze it.

09:34.600 --> 09:39.640
So there's just 1 or 2 functionalities, uh, to be written in this lecture.

09:39.640 --> 09:42.010
And after that we are done.

09:42.460 --> 09:45.590
So what we can we have already written the shift arithmetic.

09:45.590 --> 09:48.440
Right now we need to write the shift arithmetic, right?

09:48.440 --> 09:50.420
With sign extension.

09:52.860 --> 09:53.270
Here.

09:54.500 --> 09:55.220
Shift.

09:56.990 --> 09:58.310
Arithmetic.

09:58.310 --> 09:59.270
Right.

10:00.000 --> 10:02.510
With sign extension.

10:02.520 --> 10:03.660
This is for now.

10:03.660 --> 10:08.730
We will load the value of the move.

10:11.610 --> 10:17.070
Now we will move racks to negative number.

10:19.030 --> 10:22.690
Which is for loading the value of negative number to racks.

10:23.380 --> 10:25.450
Remember, this is a negative number for now.

10:25.960 --> 10:27.400
Now we will use a.

10:28.470 --> 10:37.680
As a ah, this is for shifting the racks by two bits with sign extension, which is this is also called

10:37.680 --> 10:39.480
the arithmetic shift.

10:39.600 --> 10:43.170
And after that we will store the result in result.

10:43.200 --> 10:44.570
I result.

10:44.700 --> 10:45.020
Yes.

10:45.030 --> 10:45.450
Result.

10:45.480 --> 10:48.420
I basically so result.

10:50.680 --> 10:55.600
Racks and now we will need to display the result here.

10:55.600 --> 11:00.640
So move or die fmt int.

11:02.150 --> 11:03.020
Which is followed.

11:03.350 --> 11:05.220
Address of format string two.

11:05.750 --> 11:08.450
Now we will move the RSI to.

11:08.490 --> 11:09.110
Sorry.

11:09.530 --> 11:10.490
This is for load.

11:10.490 --> 11:13.640
The address of address of message to RSI.

11:14.340 --> 11:18.380
Uh, remember, we have defined something like, uh, here.

11:18.410 --> 11:19.550
Number one shift.

11:19.550 --> 11:19.970
Right?

11:19.970 --> 11:23.690
Two dividing by four with sign expression.

11:24.730 --> 11:24.990
It.

11:25.140 --> 11:29.860
It will understand it better when we create the output for this run the program.

11:30.250 --> 11:31.690
And after that.

11:33.290 --> 11:34.370
Uh, we need to.

11:35.810 --> 11:39.980
Lord the value of result I to move.

11:41.050 --> 11:50.740
MOV rdx is result i here and move now we will move the rax which is zero.

11:50.740 --> 11:57.220
We will clear the rax register and we will call the printf as we always do.

11:57.400 --> 12:02.230
And now we will also multiply it, divide it and that's it.

12:02.230 --> 12:08.260
So multiplication will be much easier than division and you will see why.

12:08.650 --> 12:11.350
So multiply.

12:11.380 --> 12:12.640
So move.

12:13.540 --> 12:14.450
Racks.

12:16.050 --> 12:17.040
Number one.

12:17.040 --> 12:19.920
Here we are loading the value of number one to racks.

12:19.950 --> 12:23.580
We will email here, use email keyword.

12:24.570 --> 12:25.860
Number two.

12:26.070 --> 12:26.590
Here we are.

12:26.610 --> 12:32.190
Multiply we are telling the assembler to multiply rax with the value of number two, which is this is

12:32.190 --> 12:40.230
the 64 bit multiplication and we will use the move here to store the result in result.

12:40.260 --> 12:47.370
I in order to do that we will use the result I here and after that we will tell rax and now we will

12:47.370 --> 12:49.500
need to display the result here.

12:49.500 --> 12:56.340
Display the result mov rda you already know how to display the result here.

12:56.490 --> 12:59.400
Fmt int mov rsi.

13:01.980 --> 13:03.600
MOV RDX.

13:05.370 --> 13:09.790
Result II which is loading the value of result I to RDX.

13:09.810 --> 13:17.400
And now we will clear the register which is returning the value and we will call the print F.

13:17.670 --> 13:18.410
So that's it.

13:18.420 --> 13:22.140
Now we will write our division divide.

13:22.230 --> 13:25.920
Now we will call the move.

13:28.870 --> 13:29.740
Number one.

13:29.740 --> 13:34.960
Here we are loading the value of number one to racks.

13:34.960 --> 13:37.330
And now we will call the.

13:40.670 --> 13:50.120
MOV rdx zero clearing the rdx register, which is a reminder and i div here.

13:51.410 --> 13:52.340
He was.

13:53.360 --> 13:54.050
And.

13:55.760 --> 13:56.660
Award.

13:57.940 --> 13:59.350
Number two.

14:04.630 --> 14:13.090
And after that, with this here we are telling the assembler assembly to divide the racks by the value

14:13.090 --> 14:17.740
of number two, which is a 64 bit, uh, division.

14:17.740 --> 14:23.650
And this is the equation in racks reminder in RDX.

14:23.650 --> 14:26.140
And we will use the move here.

14:28.560 --> 14:29.340
Move.

14:29.370 --> 14:30.510
Result.

14:31.440 --> 14:32.220
Result.

14:32.250 --> 14:42.150
I Rex, this is the this is for storing the quotient quotient of in result I and now we will also modulo

14:42.480 --> 14:43.830
modulo here.

14:43.830 --> 14:49.710
This is for storing the reminder or restoring the reminder in modulo.

14:49.710 --> 14:51.300
Here are the x.

14:51.300 --> 14:54.540
Now we will need to display the quotient quotient.

14:54.750 --> 15:06.420
So display the quotient and now we will need to load the address of format string to move the the i

15:06.540 --> 15:10.590
fmt int mov rsi TV.

15:10.590 --> 15:15.750
This is for loading the address of message to RSI and move the.

15:18.800 --> 15:19.490
Now we are.

15:21.130 --> 15:23.770
RSI side, the X here.

15:24.010 --> 15:28.580
The result here is not the value of result to RDX.

15:28.750 --> 15:31.660
Now move the rax zero.

15:31.660 --> 15:34.450
Clear the rax register and call the.

15:35.620 --> 15:36.470
Printf.

15:37.480 --> 15:39.880
And now we need to display the reminder.

15:40.000 --> 15:42.790
And that's all display.

15:44.920 --> 15:46.150
Display the.

15:47.270 --> 15:48.410
Reminder.

15:48.620 --> 15:51.710
And here we will do the same logic here.

15:51.740 --> 15:57.260
Move by Fmt and move.

15:57.940 --> 16:03.550
RSI REM and mov rdx modulo.

16:06.410 --> 16:09.600
And after that, we will move the racks.

16:09.650 --> 16:10.340
Zero.

16:10.610 --> 16:13.480
And after that, we will call the print f.

16:14.970 --> 16:16.590
To display the formatted message.

16:16.590 --> 16:19.270
And now we need to write three instructions as well.

16:19.290 --> 16:25.050
Move rsp rbp for restoring the stack pointer.

16:25.080 --> 16:26.220
Pop Rbp.

16:28.140 --> 16:33.900
For restoring the bass pointer and we will return from the, uh, main function.
