WEBVTT

00:00.480 --> 00:01.480
Hello everyone.

00:01.520 --> 00:02.520
Typhoon here again.

00:02.840 --> 00:10.400
And today we begin one of the most fundamental and powerful journeys into low level programming understanding

00:10.880 --> 00:20.520
x86 64 assembly or understanding the registers in x86 64 assembly.

00:20.520 --> 00:26.840
So if you want to know how CPU thinks, how it manipulates data, executes instructions, and controls

00:26.840 --> 00:32.360
memory, then you must understand the registers.

00:34.200 --> 00:41.120
Now, this lecture is long, dense, and packed with everything from beginner insights into detailed

00:41.160 --> 00:47.560
breakdowns meant for feature reverse engineers and low level programmers.

00:48.080 --> 00:52.360
So you may ask here, what are the registers?

00:54.120 --> 01:02.400
At the lowest level of computing, a register is tiny, lightning fast piece of memory inside the CPU

01:02.440 --> 01:03.080
itself.

01:03.730 --> 01:10.650
registers temporarily store data that's being actively used or manipulated by the CPU.

01:11.370 --> 01:15.930
They are fundamental to every operation your processor performs.

01:17.930 --> 01:22.690
Now you can think of the registers as the working hands of the CPU.

01:22.850 --> 01:30.810
So instead of grabbing data from random access memory or Ram every time, which is much slower compared

01:30.810 --> 01:39.650
to the CPU, the CPU first grabs it into a register, manipulates it under, and then sends the results

01:39.650 --> 01:43.170
back to the random access memory Ram if needed.

01:43.730 --> 01:50.930
In x86 assembly, there are multiple types of registers, each grounded based on function or grouped

01:50.970 --> 01:52.010
based on function.

01:52.370 --> 01:56.010
The first we have g a.

01:57.010 --> 01:58.690
This is not a universal GPA here.

01:58.690 --> 02:01.410
This is general purpose registers.

02:01.970 --> 02:04.650
This perform like arithmetics.

02:06.410 --> 02:10.570
Logic and memory access.

02:12.370 --> 02:20.450
And we also have the segment registers which manage segmented memory addressing.

02:24.490 --> 02:33.170
We have the flags register which tracks the results and CPU states after operations.

02:34.930 --> 02:47.530
And we also have the instruction pointers like I, p e p and r I p.

02:49.930 --> 02:52.850
Which basically shows where the current instruction is.

02:54.730 --> 03:00.090
Now let's let's dissect each category right now.

03:01.810 --> 03:05.970
First we will start with the general purpose registers.

03:09.820 --> 03:11.460
General purpose registers.

03:11.820 --> 03:20.060
So the original x86 architecture began with 36 bit general purpose registers.

03:20.460 --> 03:21.420
These include.

03:21.420 --> 03:26.180
The first is accumulator a x.

03:27.180 --> 03:28.740
Let's actually change the color.

03:28.740 --> 03:30.260
Write it in a different color.

03:32.420 --> 03:33.100
A x.

03:33.500 --> 03:38.460
So this is accumulator used heavily for arithmetic multiplication and system calls.

03:39.300 --> 03:42.460
We have base register b.

03:44.860 --> 03:47.860
Often stores base addresses in memory operations.

03:48.020 --> 03:58.300
We have C control register commonly used in loop operations such as uh rep mov esp.

03:59.940 --> 04:04.620
Let's actually also write the abbreviation for this uh, as well.

04:05.180 --> 04:15.220
Uh, we have the X uh, which is data register, often used alongside a uh in division multiple action.

04:15.220 --> 04:25.900
Also for input output port addresses we have the source index um and uh destination index.

04:27.860 --> 04:36.620
Uh now uh, these used in string operations and array traversal, we have stack pointer uh points to

04:36.620 --> 04:37.740
the top of the stack.

04:37.740 --> 04:46.380
And we have the base pointer, uh, helps access functions, parameters and local variables within the

04:46.380 --> 04:46.860
stack.

04:49.740 --> 04:55.900
Let's also write the abbreviation so you can see it as we explained.

04:57.580 --> 04:58.660
Now here we are.

04:59.140 --> 05:05.420
Uh now this register can also be split into eight bit halves.

05:06.140 --> 05:18.390
Now for example in the A we have the A h, which is the high byte, and a L, which is the low byte.

05:18.990 --> 05:33.270
And for example, in B, we have the b h, which is the high byte low byte, not byte.

05:33.350 --> 05:34.950
Sorry, it was a bit.

05:34.950 --> 05:35.790
So remember.

05:36.070 --> 05:39.310
So eight bits 16 bits.

05:40.710 --> 05:45.030
And yeah same applies for the other registers as well.

05:45.070 --> 06:04.310
Say x to C 16 bit c eight bit d, l for eight, d H for 16 bit again and d L for.

06:06.750 --> 06:07.470
Eight bits.

06:07.670 --> 06:09.870
Since L here means low.

06:14.040 --> 06:17.440
And same goes on like this as well.

06:18.800 --> 06:25.560
Now that means you can manipulate single bytes efficiently, which is extremely useful for low level

06:25.560 --> 06:26.440
data handling.

06:26.720 --> 06:38.320
And when x86 architecture was extended into uh, 32 bit uh, also called the I.

06:40.680 --> 06:57.720
32 now these registers became the uh EAX, which is uh e a uh like e b x for the base register.

07:00.240 --> 07:04.480
E c for the counter register.

07:04.960 --> 07:05.280
E.

07:07.720 --> 07:16.520
For the data register, like s I E.

07:17.080 --> 07:17.520
S.

07:19.360 --> 07:19.760
I.

07:20.000 --> 07:21.240
And so on and so forth.

07:22.480 --> 07:30.000
And, uh, in the 64 bit, uh, which is what we call it the.

07:32.120 --> 07:37.880
In the 64 bit which written is like that x 86.

07:37.880 --> 07:40.000
Let's actually use a different color so we don't.

07:41.720 --> 07:42.120
Yeah.

07:42.520 --> 07:47.000
For example x 86.

07:48.800 --> 07:51.560
Now this is 64 bit.

07:53.120 --> 07:57.480
So remember this was the 16 bit 32 bit uh here.

07:57.880 --> 08:02.200
And the 64 bit registers we have here.

08:02.240 --> 08:07.680
Now the most used uh today is 64 bit registers, but depends on the CPU architecture as well.

08:08.720 --> 08:13.120
Um now they expand it to the Rax.

08:15.200 --> 08:22.850
Uh accumulator rb X for the base register.

08:23.210 --> 08:23.690
RC.

08:25.930 --> 08:27.970
For the contour register.

08:28.810 --> 08:38.650
R D for the data register and added from R eight.

08:39.530 --> 08:45.570
From R eight all the way to the R 15.

08:47.770 --> 09:03.610
Making 16 full general purpose register number 1234567 and from R81234567 and from the R eight to R

09:03.650 --> 09:10.090
15, it just um, 16 uh full general purpose register.

09:10.290 --> 09:13.170
And we all have the stack pointers as well.

09:13.490 --> 09:22.290
Now uh SP and uh BP also transition to and also get another meanings.

09:22.610 --> 09:25.810
Uh, so uh SP.

09:27.890 --> 09:31.010
SP turns to ESP here.

09:32.810 --> 09:40.650
P and uh E for the base pointer.

09:45.050 --> 09:50.090
Uh, now this points to the top of the stack.

09:50.450 --> 09:53.130
Changes automatically with the push and pop instructions.

09:53.450 --> 09:55.850
And for the, uh, 64 bits.

09:55.930 --> 09:59.050
Uh, it also changed in the 64 bit.

09:59.050 --> 10:04.850
We have the r s p and r p p here.

10:06.410 --> 10:10.610
Uh, here, SP stack pointer turns to 32 bit ESP.

10:10.610 --> 10:14.610
And in the 64 bit we use the r s p.

10:16.530 --> 10:20.610
So uh, RSP is pointing to the top of the stack.

10:20.850 --> 10:25.940
Changes automatically with the push and pop instructions and beep.

10:26.620 --> 10:27.380
Beep beep.

10:27.420 --> 10:30.100
These are basically the base pointer as well.

10:30.260 --> 10:34.020
Base pointer to reference the stack frame, which is this.

10:34.460 --> 10:36.580
We will use this in a function calls.

10:37.460 --> 10:46.340
Now every register can be accessed in parts like rax x x like like this rax.

10:46.340 --> 10:56.780
We can use the rax to the e to the x here.

10:57.340 --> 11:04.700
And for the lowest we have the a, l and a h, which I have explained here.

11:06.060 --> 11:16.460
Number and the bits increase and increase as from left from right to left in this diagram uh, which

11:16.500 --> 11:19.220
allows for flexible manipulation of data sites.

11:19.220 --> 11:27.300
So if you, if you don't need the 64 bit registers, um, but you're competing on the 64 bit CPU.

11:27.700 --> 11:28.900
You can just use a.

11:29.460 --> 11:31.380
So from this to save the.

11:31.540 --> 11:38.580
From computing power, which you will learn that more deeply in next lectures.

11:39.900 --> 11:44.820
Uh, now let's also explain the instruction, uh, pointers.

11:46.220 --> 11:51.740
In the next lecture, uh, this was the part one of the first lecture.

11:51.780 --> 11:57.020
Uh, this is, as I said, from the starting of this, uh, lecture.

11:57.300 --> 12:03.060
Uh, these are very important, uh, for learning assembler languages.

12:03.060 --> 12:07.060
It doesn't matter if it's an an R or another assembler language.

12:07.180 --> 12:14.220
If you know the base understanding of this, how assembler works, uh, you can apply the same principles

12:14.220 --> 12:23.460
on R or other Masm or other assembly languages here.

12:23.860 --> 12:24.980
So thank you for watching.

12:25.020 --> 12:27.740
I'm Tiffany and I'm waiting you in next lecture.
