Hello.
Welcome back.
In this lesson, we are going to demonstrate how to write assembly code using the Kubi d e.
I'm going to create a new project from over here, new SDM 32 project.
My boat selector is going to load up.
So here we go.
So I should point out.
If you load if the.
The project selected a target selector loads up and it doesn't show this Panio over here.
Simply click a console and start the project creation project and start a project creation process again.
Um, cause sometimes when you try to create a project and it tries to load the, um, the target selector,
it doesn't load everything.
It doesn't load the part that allows you to search for your board.
If you experience the click console, there is console down here.
There is console here.
If you experience that, just click console over here and start again.
Yeah, I think Cube I.D. two has a number of bugs that, you know, updated versions.
Would, um, would you sort of get rid of.
Um, yeah.
Look at what I'm having here.
So the, the pano disappeared.
Just what I was talking about.
So in this case, what I would do is simply console and then just start again, click console over here
and then start again.
New look at this.
Oh, goodness.
OK, SDM 32 Kube SDM 32 Project Knocking Project.
So it's going to load up the targets elected again, and this time I hope you load it up properly.
So I'm gonna search my boat again.
Do pardon the arm.
The resolution here.
It's from the cube I.D..
It's not from my side.
ASTM 32 by boat is estimated to have four one one.
Just search a boat here.
And this is the same screen we find on Cuba mix.
So there's nothing strange.
Just search your boat, your microcontroller if you are using a different microcontroller and then go
ahead and select it.
So once your board is selected, you just click next.
And then you give your project a name.
I'll call this simple assembly.
I'll keep everything the same.
Or click next and a click finish over here.
And it's going to create a project.
It says this.
This kind of project is associated with Cuba.
Max, do you want to open this perspective?
No.
I'll say no.
I think it would open it regardless.
Right.
So the setup is complete and we have this here.
I'm going to close this.
We don't need as we write an assembly code.
And then, um, this is our project.
We come to call our source file is here in the source folder.
And then, um, our.
We don't need all of this.
We don't even need may not see.
I'm simply going to delete the main dot.
See.
Right.
Click, click, delete.
Over here.
Like this.
And then.
Okay.
We don't need the rest, but we can keep them there.
I'm going to create a main dot s file.
Right, click.
New file.
I'll give this a name mean, but miss.
Right.
And this is all me.
Yes.
So we write the assembly code in here.
OK.
So to write assembly code, we start with the directives.
The directives are not they are not instructions.
They they tell the compiler how to compile the code.
So in assembly language, you could have two different compilers of the same instruction set to different.
They would have this India directives.
Well, that's what that means, is that the code we're going to write here should run exactly the same
way on the, um, um, compiler or the AB assembler, I should say, our symbol.
No compiler, cause the assembly code is assembled.
It's not compound.
So the ARM assembly will run this, just that the directives would have to change.
So over here we're using the GCSE assembler and we start off by using the section direction to say this
is a code section.
We just see a DOT section.
And then we see it of text to say this, who hold a code and then we can use the C.P.U to indicate to
ACP.
We are using we use in the cortex and forward to another directive that is the C.P.U we are using.
And then we can use the DOT global and global without a dot GPL.
And then we say mean to make this the subroutine made this label made to make it accessible from a file
outside of this one.
So I say mean and then I'll come over here and then I'll create to mean so many is label or create to
me like this.
And then we start off by moving, we're gonna say move into register our five zero x zero x um you're
X six four.
And I think this is the number hundred.
This is just for testing to show that we can write assembly code here.
Now we're going to say move into the register.
AR4 gonna move less, add a number the number zero.
How about that.
And then once that is done, we're going to create another label here.
We called Loop so that we can jump to this label.
And over here we are going to see how well we we say @ @, the content of our five at one at the number
one to the content of Register R5 and then start a resort in R5 would do that by writing this.
We take this operand we added to this and then this the destination.
So the content of this register, add this to it, then store it here.
Right.
And then we see our for Hobaugh add the content of register our four.
I'd want to it.
I'm writing it in this way to let you understand.
So first we take the content of our four, we add one and then we start a resort back into our four.
Right.
So we call in this loop.
And then, um, let's see, what else can we add to this experiment?
Think we can simply test this out?
Cause this is simple assembly just to test that we can create and run assembly code.
So we're going to end, but we're going to branch to this label here.
This label is not accessible yet.
So we're going to make sure when we execute this instruction, we execute this next one.
And then we would execute a third one that would bring us to this label.
So we use the A B instruction, which means branch.
And then we passed the name of the label like this.
And we use the end directive here to indicate this is the end of our assembly assembly program.
So control is to save.
And then, um, yeah, we can build and see what we have.
Click over here to build.
It's built in.
It's Putin.
We have three errors.
Let's see.
I'm going to open this up.
What does it say?
Immediate expression requires.
Okay.
Yeah.
I forgot to put this here, okay.
If you're using a number, you have to put the number sign harsh sign like this.
So that is one of our era of click to build and see what this is, what created the other arrows build.
Okay.
It's looking good so far and it's built successfully.
No warning.
Okay.
So now let's go to our debug fuel to check our registers.
What indeed we get these values stored in the registers.
Click over here.
Debug SDM 32 to.
Oh.
Okay.
I'll click okay over here.
It's open in.
And it's finished.
Open it.
So we have different views here.
We have the live expression, if we have break point.
We have juice.
We have registers.
If you don't have any of these views here, you can come to window, show view and then talk about any
of them on.
So if you didn't have the Register's view, you can simply click to have it.
So click on Registers View and oh, expand this.
And this will give us a view of our general purpose.
Redish This.
So this is our Schiro.
This is the value of our zero now.
This is our one.
Our two are three or four or five.
And then the other registers are down the course we have, we have, we are floating point registers.
That's why we see the D.
But we look not just the R registers.
The general purpose registers to use this to execute our instructions line by line.
Best means step into this means step over.
This means step return.
We're going to use this step into.
And whenever you see this arrow pointing to a line, it means this is the next instruction to execute.
This is what is going to be executed next.
So I'm going to click on to step into and it's executed this.
What did this do?
Did this moved a zero x six four to register our five?
Let's see.
What are our five.
Has this.
US can see our five was the number one hundred.
One hundred in hexadecimal form is zero x six for the next says.
The next instruction says move to number zero to register our four.
So let's run this and see what a r four.
B zero.
Well, our voice currently zero.
So there'll be no difference.
But let's run it regardless of click over here.
Step in two.
OK.
So nothing has changed.
We know that the next instruction says branch to the label loop.
So if we execute this, we want to jump to this place branch to this place or click to execute this.
OK.
And now we are here.
So the next instruction says go to the content of register are five.
And add one to its content and store the results back into our five.
So currently our register AR five has the number one hundred.
After this, an instruction we expected to have the number one hundred and one because we are performing
one hundred plus one.
So click over here.
Step into.
And I can see are five.
One to one, right?
So next it says go to register for take it content, add one to it to our four plus one, and then store
the resorts back into our four.
Click here to step in to.
And we just executed.
And then I can see her for one.
And that's the end of our program.
OK.
So this shows that we can run our assembly code, which cube idea?
And that is how we create an assembly project.
You simply create your project.
You delete the M the main dot s file demand or C falling creates a main dot s file.
And it's important that we call this.
Where is it?
It's important.
We call this main dot.
We call this label made because in the in the system.
Uh, reset handler.
It s looks for this.
This subroutine called me as its starting point.
So if we give it a different name, it wouldn't work.
So let's say I give it a different name.
Five, for instance.
Let's see, the starting label is called MI five, and I'm making this accessible.
If you use the global, it means you want to make it global so the other files can access it.
So let's say this is it and I click here to build.
OK.
What does it say?
We have two arrows.
What does it say over here?
Return exit studies.
So basically what is happening is a what quote has no starting point.
So that is why we are using the word mean.
If we had a main doxie fall, then we can give our label here in your name because the starting point
of the program will be in demand.
Ötzi.
But because we do not have me not see, we use this control.
S or build and then the arrows should disappear.
No.
As you can see, no longer have any arrows.
Right.
So that's all there is.
If you find in the course useful for just, you know, leave it in the in the review area.
OK.
I just can't help it.
Before you go, I would want to show you why Maine is the is the word that we need to use to make it
work.
Okay.
So we need to go to our system d'hote.
S fault and take a look at the routine known as the reset handler.
And this is the first portion that is executed whenever your boat starts up.
Okay.
After the boot sequence, of course, um, we come to over, uh, this forward here setup.
And then there was this file on, uh, dot.
S file.
It s called this long name start up on the score, SDM 32 f F4 and then dot s or double click to openness.
And what we're looking for is the reset handler.
So this is the reset handler.
Right.
This is how it starts.
It's.
This to S.P..
Espey means stop points, so you'd need not know that.
But important thing is, after it's executed, it punches to this other label known as loop copy data
in it.
So let's go to Leupp, copy data in it and see.
This is loop copy data in it.
So this is still part of the reset.
I'm glad that the reset unluck comes here and then this execute these lies one by one.
And this finally branches to loop few zero P.
S s.
So this is our destination.
So let's also branch.
Let's find this routine loop feels Europa s as when we take a look at it, we see what happens.
It executes this, execute this, this.
And then it?
S branches two system units to initialize the system.
And then finally, it does B l mean it's branches to the applications entry point.
So this is why we have to make sure we have the main existing in our application because it's going
to branch to a label known as Main.
If we have may not see the label will be created, if we have just assembly language.
We have to make sure our assembly language has a main in there so that we can branch.
So let me show you something.
Let's say I change this mean here to mean to.
Now let's build our assembly language program and see a click over here to build.
And we have two errors, right, cos we have men, two over here.
What does it say on defined reference to me too?
So we have main two over here.
And then let's go to our assembly that?
S over here.
And then I'm going to change this to mean two.
And then this to me to control.
S to safe.
And then click away to build.
And as you can see, because I change it to mean to.
We can use it to mean to.
We can use mine to hear.
So if you want to use a different name, you would have to change it from the reset handler.
But, yeah, we don't want to do that.
Now you understand why we use me.
If you don't.
Of course you can live it in the questions and answers area.
OK.
So I'm going to leave this.
I'm going to change it back to me so you can even use the word to start or your name.
But the reset handler has to branch to that label.
OK.
So that's all there is.
And have a nice day, my friends.