Hello, my name is Stefan.
And in this lecture we are going to develop our project calculator project further here.
Now, as I always do, we will I will explain the code while I'm writing it.
And also, uh, when I'm done.
So now we will need to develop our BBS section here, uh, which we will just uh, define two variables.
So section BBS, result result I rescue here.
One result or modulo here is rescue one as well.
And here we will define text section where we will our code will be written.
We will define global main define the main function.
We will here write push RVP move.
RWP rsp.
You already know what that means.
But I will also.
I will explain it again.
And what we're going to do is we will display the numbers here and we will write five instructions,
move the i fmt.
We need this tabs.
So basically we are loading the address of format string to RDR.
Remember this format string is the number here.
Fmt move here.
RSI.
This is number one.
This is the this is for loading the value of number one into RSI.
Here.
Number one is 128 and number two is 19.
And here we will do the same for number.
To.
So move.
Are the eggs.
Number two and move.
Racks.
Zero.
And after that we will call a printf to display the formatted message call.
Printf.
And after that we will need to write the adding here.
So move racks.
Number of.
Number one.
At.
Racks.
Number two.
Here in this here we are loading the value of number one into racks and.
We are doing the same for adding the value of number two to racks.
But here we are loading and here in this here we are adding here, which you will see the difference
right now and result.
We will store the result in this result I reserve so.
Result.
I hear.
Tracks.
And after that, we need to.
We need to display the result as well again.
So display the result.
So move.
Ready?
Fmt fmt integer, which we define somewhere here.
So.
Empty end.
Now what we're going to what we are doing here is we are loading and loading the address of format string
to RTI and MOV RSI.
Some.
Am I here?
This is the.
This is for loading the address of message to RSI.
MOV rdx.
And with this we will.
Actually, yeah.
Uh, uh, with RDX, we will need to load the value of result I result here uh, two, which is.
Or we define it as a reserve.
Who are the.
And after that move.
RDX.
Or racks.
Racks.
Zero.
With this, we are clearing the racks register, which is basically returning the value and after that
we will call them printf.
Which is calling primitive to display the formatted message.
Printf?
Yeah.
And after that, we will need to create our subtracting here.
And after that I will begin to explain these codes.
So.
Acting and move racks.
Number one.
Here we are loading the value of number one into racks sub.
Racks.
Number two.
Move.
Of result.
Rags.
Here we are, storing the value.
Storing the result in a result.
Result I.
And here we are.
Subtracting.
Subtracting the value of number two from rags.
And now we will need to display the result.
Displaying the result.
And here.
That's.
So here what we're going to do is we will load the address of, uh, format string to RTI.
RTI.
And FM to integer move.
RSI.
If you are here we are loading address of message to RSI.
Move.
Are the.
This is fall result I.
They are loading the value of result I to RDX and now we will move our r r a x.
Here we are clearing the x register, returning the value again, and we will call the print.
Our code is not yet done.
We need to add another mathematical arithmetics as well.
But here for this lecture, I will explain this.
So, uh, here.
At first you remember we had this push and move.
RWP rsp.
But we will start from here firstly.
So with this here move ah, the I fmt we are moving the memory address of the format string fmt into
RDA register and RDA will be used as the first argument for this printf function.
And here we are moving the.
Value stored at the memory location pointed to by number one into the RSI register.
And this loads the value of the first number for displaying.
And here we are moving the value stored at the memory location pointed to by number two into the RDX
register, and this loads the value of second number for displaying as well.
And here we are calling the um.
And here we are calling the.
Printf, which calls the string function to display the formatted message using the provided, um,
argument like RTI, RSI and RDX here.
And after that we have moved racks number one.
This is for moved moves.
The value stored at the memory location pointed to by number one into the racks register.
And this.
This loads the value of the first number for arithmetic operations.
And here we are with this.
Here we are telling.
Telling the assembler to add the value stored at the memory location pointed to by number two to the
value in rax register.
So this result the result is stored in Rax representing the sum of two numbers.
And here we are storing the value in the rax register which is sum of the numbers.
Sum of the numbers.
Summary of the numbers into the memory location pointed to by result I here.
And we are.
In display here.
I move Fmt and RDL will be used as the first argument for the printf function and here RSI will be used
as the second argument for the printf function here.
And this loads the.
This loads the result of the addition operation for displaying.
So this clears the rax register, preparing it to be used as the return value for the printf function.
And here we are calling the printf function to display the formatted message using the provided arguments,
which is RDA, RSI and RDX.
So this subsequent subtracting section follows a similar pattern with the sub instruction to subtract
the second number from the first number and the same process for displaying the difference.
And please.
Here.
Keep in mind that this printf is callable function from an external library.
And.
As you can see here, it's being used for output purposes.
And as you can see here, we almost all fully completed we completed 50% of our program, which we will
continue that in our lecture in in our next next lecture.