In this video, we'll be writing an ARM assembly program to add two numbers.
ARM follows a risk architecture where everything you need to perform, you need to write to registers
and cannot perform operation on memory.
We need to perform operation on registers.
So if you see an example here.
So if you see this one, as we said, it has a particular syntax where you have uh a label colon.
Label colon is one.
And then you have instruction and then you have comment.
So here you see we are only having a assembler directive.
Anything that starts with a dot is in a directive.
The dot text is an assembly directive which says that following instructions have to be assembled into
the code section rather than the data section.
So every instructions which we write will go to the code section.
I mean, whatever we are writing below, uh, dot text will go to the code section.
And then you have a label known as start.
And then you have colon and this.
Operation.
This is an instruction.
We are saying we will move the value of R0 to five.
So very simple, right?
Instead of writing 0004 and e all e a is zero three and all, whatever the opcode, if you write this
one, this is easy to understand.
We are here, we are specifying, we are moving the value of five in R0.
And here we are specifying.
We are moving the value of four in R1.
And then we are adding r2, r1 and r0.
Here what you are saying add the value of r1 and r2 zero and store in R2.
And then we are saying perform a while one loop because our operation is completed.
So this is a very simple example where we are.
Performing addition of two numbers using assembly.
I'll copy this and save this in a file known as S file with an extension S.
If I say this file add dot s to say assembler source.
So yeah.
So it is knowing this is an assembler source.
If I change this value to add dot c, let's see what happens whether file command says this c or not.
So sorry.
Add a C and say file add dot c still says assembler source.
So file is very intelligent.
It knows what is in present in the actual file content.
So now we have add dot s uh assembly code is present.
We need to convert this into an opcode.
Right.
We need to convert this into an operational code which CPU understands.
For that we need to use a tool known as assembler.
Assembler converts this thing to an opcode.
So I will use this command instead of using S a s is for x86.
We need to cross compile this one.
So I'm using arm nun s add dot s hyphen o add dot o.
Now I got a file which is add dot o again.
Now here object file is there.
It is for compile for arm and it is a 32 bit uh relocatable file.
Again we'll not go into Elf for now.
We are trying to do a basic, uh, bare metal programming where there is no, uh, OS involved.
And if you, if I pass this to this, uh, also, it will not able to it will not able if I pass this
file to my CPU or the boot connects boot, it will not understand.
Now I need to generate an executable file again.
I will be using ld command and then I am specifying the t text.
So I am specifying like addresses should start with address zero.
So t text is used to uh assign labels.
So instructions will start from address zero.
So I'll run this command.
Now I will not be running the LD command.
I'll be running um nun LD and I am saying start at 000 and give me an elf file.
Take this as input.
So I gave wrong this one.
So it gives me a warning message saying cannot find entry to simple start.
You can ignore this one.
Now I have a file add dot elf.
It is an executable.
This was a relocatable.
This is an executable and it is also Elf.
But I cannot pass this file to the qemu.
It needs a binary file.
So what?
I can see the symbols whatever are present using Ntlm command so I can run um NM.
It will give me what all symbols are present as a start and stop, which are present in the text segment.
And this is undefined.
Underscore start is undefined.
And that's the reason it is giving cannot find symbol underscore start now.
I can also change the base address by using a different value for t text.
So here I am giving a different text value.
And if I see NM you can see the addresses have been changed.
So that is given this address here it was given zero zero.
But now it is giving this address.
Let's change back to the actual thing.
Now it has zero zero.