And now that's it.
We have completed our program and it's running, as you can see.
We just have some like, uh, three typos here.
As you can see here in line 7109 and 135.
So in order already fix that and just the regular typos here like a.
Are as all Thai here, like the 1 or 2 keyword typos I fixed it with here.
Now it's fixed.
As you can see, it's running.
I also, uh, the.
Publish the fixed one here.
That is not a big deal.
Now, in this lecture, what you're going to learn is you will learn all of the registers and the.
I will explain all of the things that we did in this code here.
And as you can see, it's almost 150 lines of code.
So.
Now let's start from the assembly.
The start from the increment here because we already explained the previously code.
Here before the increment.
So here we have increment, right?
So.
We are using the as a first assembly here.
We are using the this instruction here.
This instruction moves the value stored in the memory location referred as number one into the Rax register
and it's loading the value of number one into the register for manipulation.
And I see here this is the instruction here.
This increments the value in the rax register by one, and in this case it's incrementing the value
of number one by one.
Here, as you can see here, it was 1 to 8 and now it's 129.
Right.
And here we also have move result i rax this is this instruction moves the value in the rax register
which now holds the incremented value to the memory location pointed to by result i and it stores the
result of increment operation.
And here we are displaying the results in this case.
So.
The RDA register is loaded with the memory address of the format string fmt integer.
So this string will be used in the printf function to format the output.
And we also have the RSI and C here in C.
So this RSI register is loaded with the memory address of the message string in C here.
So this message will be used in the printf function to provide context for the displayed result.
I want to also here.
As you can see, it's tradition.
Number one, incremented.
And also we have move the result.
I hear the RDX register is loaded with the value stored in the memory location pointed to by result
I.
So this value represents the result of the incremented operation increment operation and we have the
move rax and this instruction sets the value of Rax register to zero and it prepares Rax to be used
as the return value when the printf function call is complete.
And this instruction calls the printf function to display the formatted message and the arguments for
the printed functions are loaded into the RTI, RSI and RDX registers.
And we also have the incrementing here.
So similar to before, this instruction moves the value stored in memory location reference by number
one into the Rax register and it's loading the value of number one into the register for manipulation.
And we have the D a C here.
So the the the instruction decrements the value in the rax register by one.
And in this case it's decrementing the value of number one.
And we lastly, we have the result i rax mov result i rax this instruction moves the value in the rax
register register which now holds the decremented value to the memory location pointed to by result
i and it stores the IT stores the result of the decrement operation.
And now we have the displaying the result.
So.
This is basically almost the same as the previous incrementing operation here.
And yeah, the code goes same and same here.
Just changing three registers, instructions and variables.
But the code structure is almost the same.
But here we have the in the display result divide.
And now here we in the shifting code side of the code, we have something interesting here which I will
explain that here.
But we have SA and as a register and sal, we should have somewhere here.
Not division.
Sal.
So.
This instruction moves the value stored in the memory location referenced by a number one into the Rax
register, and it's loading the value of number one into the register for manipulation.
And here we have Sal rax two.
The Sal instruction, also known as c h l this which is meaning the show shift logical shift logical
left shifts the bits of the rax register to the left by two positions, effectively multiplying the
value by two.
And we have the move here.
This instruction moves the value in the tax register which now holds the shifted value to the memory
location pointed to by result I and it stores the result of the left shift operation.
And we us what we have here, we are displaying the result with as we always do.
This is the opposite, opposite for this.
Here we are.
Instead of using Sal, we are using a here.
And.
Yeah, that's it with our program explanation here.
And in next lecture, we will also run this program here.
Explain it, uh, deeper.
And we will analyze this program as well.
And before the closing, stopping this lecture, I want to explain the.
Registers as well.
Again, because we need to repeat it until we.
Know it better.
And I will start with R.D. here.
So this is a general purpose registers often used to hold the address of the format string to be used
with the printf function.
And it is one one of the arguments passed to the functions.
And we also have RSI.
This is a general purpose register also used for holding arguments to function.
And in the code it's utilized to hold the values of numbers or messages that need to be displayed.
And we also have RDX.
This is the general purpose registers as well, often used to hold additional arguments to functions
and in the code it is used to store values such as the result of arithmetic operations before they are
displayed.
And we also have the r BP.
We use that somewhere here r BP here.
Let me find.
Yeah.
RVP.
This is a stack pointer register.
This is points to the top of the stack and it is adjusted to allocate and deallocate memory for local
variables and function calls.
And we have the rags, RTI, RSI, RDX, Rbx and RSP are part of the x86 64 calling convention and are
used to pass arguments and manage function calls between the caller and Callie.
And we also have in C and D, a C Here we use the incrementing and decrementing operations.
Uh, it should be somewhere here.
I see.
And I see here these instructions, uh, for incrementing and decrementing a register or memory location
by one, respectively.
So they are used to perform simple arithmetic operations quickly.
We have the add and sub here.
This instruction that adds a value to a register or memory location, and it is used for addition parents
and for sub.
Here is this instruction that subtracts a value from a register or memory location and it is used for
subtraction operations and we also have s a L and s r a s a r here, which should be somewhere.
Here's are s a are here and.
Sal.
So these are the shift arithmetic left and shift arithmetic right instructions are used for shifting
the bits of registers or memory location to the left or right, and they can be used for multiplication
and division by powers of two respectively.
And we also have here I'm u l you should see somewhere here instruction use.
This instruction is used for sine multiplication of two values.
It is often used with two operands and the result is stored in the destination operand.
And we have it here.
This is this instruction used for sign division and it divides the contents of the accumulator by the
specified operand and stores, the quotient in the accumulator and the remainder in the specified register.
And we have the printf.
This is a function from the C library used for formatted output.
And in the code it's called with arguments stored in registers and displays the formatted message to
the console.