Hello everyone.
Typhoon here again.
And today we begin one of the most fundamental and powerful journeys into low level programming understanding
x86 64 assembly or understanding the registers in x86 64 assembly.
So if you want to know how CPU thinks, how it manipulates data, executes instructions, and controls
memory, then you must understand the registers.
Now, this lecture is long, dense, and packed with everything from beginner insights into detailed
breakdowns meant for feature reverse engineers and low level programmers.
So you may ask here, what are the registers?
At the lowest level of computing, a register is tiny, lightning fast piece of memory inside the CPU
itself.
registers temporarily store data that's being actively used or manipulated by the CPU.
They are fundamental to every operation your processor performs.
Now you can think of the registers as the working hands of the CPU.
So instead of grabbing data from random access memory or Ram every time, which is much slower compared
to the CPU, the CPU first grabs it into a register, manipulates it under, and then sends the results
back to the random access memory Ram if needed.
In x86 assembly, there are multiple types of registers, each grounded based on function or grouped
based on function.
The first we have g a.
This is not a universal GPA here.
This is general purpose registers.
This perform like arithmetics.
Logic and memory access.
And we also have the segment registers which manage segmented memory addressing.
We have the flags register which tracks the results and CPU states after operations.
And we also have the instruction pointers like I, p e p and r I p.
Which basically shows where the current instruction is.
Now let's let's dissect each category right now.
First we will start with the general purpose registers.
General purpose registers.
So the original x86 architecture began with 36 bit general purpose registers.
These include.
The first is accumulator a x.
Let's actually change the color.
Write it in a different color.
A x.
So this is accumulator used heavily for arithmetic multiplication and system calls.
We have base register b.
Often stores base addresses in memory operations.
We have C control register commonly used in loop operations such as uh rep mov esp.
Let's actually also write the abbreviation for this uh, as well.
Uh, we have the X uh, which is data register, often used alongside a uh in division multiple action.
Also for input output port addresses we have the source index um and uh destination index.
Uh now uh, these used in string operations and array traversal, we have stack pointer uh points to
the top of the stack.
And we have the base pointer, uh, helps access functions, parameters and local variables within the
stack.
Let's also write the abbreviation so you can see it as we explained.
Now here we are.
Uh now this register can also be split into eight bit halves.
Now for example in the A we have the A h, which is the high byte, and a L, which is the low byte.
And for example, in B, we have the b h, which is the high byte low byte, not byte.
Sorry, it was a bit.
So remember.
So eight bits 16 bits.
And yeah same applies for the other registers as well.
Say x to C 16 bit c eight bit d, l for eight, d H for 16 bit again and d L for.
Eight bits.
Since L here means low.
And same goes on like this as well.
Now that means you can manipulate single bytes efficiently, which is extremely useful for low level
data handling.
And when x86 architecture was extended into uh, 32 bit uh, also called the I.
32 now these registers became the uh EAX, which is uh e a uh like e b x for the base register.
E c for the counter register.
E.
For the data register, like s I E.
S.
I.
And so on and so forth.
And, uh, in the 64 bit, uh, which is what we call it the.
In the 64 bit which written is like that x 86.
Let's actually use a different color so we don't.
Yeah.
For example x 86.
Now this is 64 bit.
So remember this was the 16 bit 32 bit uh here.
And the 64 bit registers we have here.
Now the most used uh today is 64 bit registers, but depends on the CPU architecture as well.
Um now they expand it to the Rax.
Uh accumulator rb X for the base register.
RC.
For the contour register.
R D for the data register and added from R eight.
From R eight all the way to the R 15.
Making 16 full general purpose register number 1234567 and from R81234567 and from the R eight to R
15, it just um, 16 uh full general purpose register.
And we all have the stack pointers as well.
Now uh SP and uh BP also transition to and also get another meanings.
Uh, so uh SP.
SP turns to ESP here.
P and uh E for the base pointer.
Uh, now this points to the top of the stack.
Changes automatically with the push and pop instructions.
And for the, uh, 64 bits.
Uh, it also changed in the 64 bit.
We have the r s p and r p p here.
Uh, here, SP stack pointer turns to 32 bit ESP.
And in the 64 bit we use the r s p.
So uh, RSP is pointing to the top of the stack.
Changes automatically with the push and pop instructions and beep.
Beep beep.
These are basically the base pointer as well.
Base pointer to reference the stack frame, which is this.
We will use this in a function calls.
Now every register can be accessed in parts like rax x x like like this rax.
We can use the rax to the e to the x here.
And for the lowest we have the a, l and a h, which I have explained here.
Number and the bits increase and increase as from left from right to left in this diagram uh, which
allows for flexible manipulation of data sites.
So if you, if you don't need the 64 bit registers, um, but you're competing on the 64 bit CPU.
You can just use a.
So from this to save the.
From computing power, which you will learn that more deeply in next lectures.
Uh, now let's also explain the instruction, uh, pointers.
In the next lecture, uh, this was the part one of the first lecture.
Uh, this is, as I said, from the starting of this, uh, lecture.
Uh, these are very important, uh, for learning assembler languages.
It doesn't matter if it's an an R or another assembler language.
If you know the base understanding of this, how assembler works, uh, you can apply the same principles
on R or other Masm or other assembly languages here.
So thank you for watching.
I'm Tiffany and I'm waiting you in next lecture.