Hello, my name is Stephan, and in this video lecture we will delve into the assembly code, which
we will write in calculator, dot, asme file, and this code will demonstrate various arithmetic operations
on numbers using the x86 64 assembly language, and I will also provide comprehensive explanation for
each register and variable used in the code, helping you to understand how the calculations and operations
are carried out step by step.
Now let's open our assembly here and close our previously open terminal.
We will develop it using this and create a new project.
Clear the previous project here.
PM.
I mean the the default code here and here.
We will save it on the assembly.
We will create a new folder, let's name it Calculator.
And calculators.
That's it.
Now, let's name it the calculator.
Calculator.
Dot.
We will declare an external function print f for later use.
So external print f.
Actually decrease the brightness a little bit.
Okay, that's better.
Now what we're going to do is we will section.
Section.
We will cut the section data.
Here.
We will define a 64 bit floating point number with a value of one.
To right.
And number one.
BC for creating floating point numbers.
And we will, uh, give it the value.
One 128.
Number two is going to be, uh, 19 as well.
We will define another 64 bit floating point number with the value of 19.
And we will define a signed 64 bit integer with the value of -12.
Negative number.
So let's make it.
Here, so a negative number DQ as well.
So.
And 12.
And also keep in mind that these are not necessarily floating point numbers.
So you can you can also they can also behave like integers here.
And this is the first number for arithmetic operations.
This is the second number for arithmetic operations.
And this is a negative number to demonstrate sign extension.
And it can also be positive.
We just name it just nick number and we will format the strings for printf function as well.
So we will define fmt DB.
And here the numbers are old.
And here.
Ten zero and we will use fmt int.
I will explain all of this.
After completing this section here.
Like the code section.
I will explain after writing this code.
So s d here again.
And zero.
So me here.
The be here.
The sum is.
And TV.
They pay the difference?
Null terminated strings here.
These are all the null terminated strings.
And I see.
I.
So here.
Number one, incremented.
Null termination.
E.
A c i.
Keep.
Number one incremented here.
Zero as well.
Sally.
EB.
Number one shift.
Left.
Shifts left to here.
X four.
Zero again.
S s a r.
A here.
Number one shift, right?
Right to.
Which is divide by 2 or 4.
Zero and s a r i.
X.
Number one.
Shift, right?
But this one will be shifted with the sign expression.
Us with.
So in the expression here.
Let's add a termination.
Add multi.
We just need to write three lines of code and after that I will explain registers and everything here.
Here.
TB.
This is the the product.
And here this is the integer coefficient.
The integer.
And as.
And lastly, we have the Remy here.
The be here the modulo.
Is.
Zero.
Now that's it with our code for now.
Here we will add also, we will also add more codes here.
Here we just developed a section data here.
Now the the registers, um, like the general purpose registers are used to hold data and perform arithmetic
operation, which we will learn that in next lecture.
But firstly, what we're going to sing here is at the second line of our program here we are declaring
an external function printf that is used in another module like C library, and this allows the assembly
code to call the printf function for output.
And in this data here we are declaring a section of memory where initialized data is stored.
The number one, number two and the negative number are initialized with a specific values for arithmetic
operations.
And.
And we also have the format strings here.
And here the first format string does that here, this fmt here.
So this format string is used to display the values of two long integers.
The LD and the LD here, as you can see.
So LD is a placeholder that will be placed with the actual values of the long integers.
And ten here represents the Ascii code for a new line character like the new line character.
This here.
And after that, so we have the new line and this is the zero indicates the end of the string, which
is a null terminated string here to mark its completion.
And also we have here is let me actually fix this mask.
Also, we have here the fmt, uh, integer here.
So the this form of string is used to display a string followed by a long integer.
As you can see here, this is a string.
This is a long integer and the S is a placeholder for a string.
And the L is a placeholder for a long integer.
And ten here represents the Ascii code for a new line character as well.
The this is the new line character and.
This will cause the new line to be printed after this value.
And this zero here indicates the end of a string.
It's also called the null terminated string.
And we also have the Sumi here as.
You, am I?
So this format string is a message to be printed before displaying the sum of two numbers.
The string simply states the sum is and zero here indicates the end of the string, which is a null
terminated string.
And we also have d here d i f i.
Similar to the previous one.
The this format string is a message to be printed before displaying the difference.
Uh, with the difference of two numbers.
The string states, the the differences and zero indicates the end of the string.
And also we have a i n c i.
This is the format string message is to be printed before displaying the increment value of the first
one.
The string just simply states number one incremented and zero indicates the end of the string.
So.
We have the same here.
And that's it.
And yeah, that they are basically the same here.
They are just a string we are attaching to this variable names and so on.
So this format strings are essential for presenting clear and informative output messages when performing
arithmetic operations and manipulations on the provided numbers so the placeholders within the format
string will be replaced with the actual values like these placeholders.
Here's LD and so on.
Uh, so they will they will be replaced with the actual values during the printf function called the
null termination at the end of every string here is crucial for proper string handling in C and other
low level languages, like in assembly language as well.
So this code essentially sets, but actually so you don't add the null terminated string characters
manually just handles it automatically.
Now, this code here essentially sets sets up data values for my strings and external function declarations
for performing arithmetic operations on the provided numbers and demonstrating various manipulations.
So the format strings are used with the printf function to display the messages and computed results.
So the x86 64 assembly registers are key elements in executing the arithmetic, operations and manipulations
outlined in this code.
I'm awaiting you in next lecture for continuing our project.