The output file, which was created by LD, is in a format called Elf, and there are various file formats
available for storing executable code.
One of them is Elf for Linux Windows users.
P format.
But this all formats are useful when you have an OS but you are not having an OS.
We are running code as a bare metal.
We don't have an OS, so this expects we need to convert our code into a binary format.
A file in a binary format contains consecutive bytes from a specific memory address.
So we have a command which converts Elf into a binary like obj copy command.
It is used to convert between different object file formats.
So if you see this command obj copy hyphen o the file name which you want to give to the binary file
input.
This is the output format input file and output file.
So if you see I want to convert elf into add dot bin.
And this is in a binary format.
So I will run this command here.
So if I sorry this file is not having uh if I do Hexdump atlff it is having longs uh very good amount
of code.
So l s minus l h add dot elf.
It is having like 65 kb, right.
But we have only written very few instructions in our add s.
We wrote only like uh, one only these are the four instructions.
This is not instruction.
This is just a label which is helpful for assembly language.
So we only wrote four instructions so it should be only 16 bytes.
But we are having almost 65 k.
And this is not correct.
Right.
So we need to see if we have this instruction where we are E3A0 is where I am moving R05 and E3A01004
is where I am moving four in R one.
Then I am performing add I have this.
For performing add and then to branch and perform a loop.
I have this, so I only need this for opera for its instructions and whatever extra is added by elf,
which is not useful for the bare metal programming where there is no OS.
Elf is only understood by Linux kernel, not by the processor.
So we need to convert this into this format.
OBJ copy hyphen o binary I need to say a input file.
First I need to give an input file, which is add dot elf and add dot bin.
Now if I see I ls minus lh add dot bin.
This is only 16 bytes.
This is what you wanted, right?
16 bytes hex dump I will do add dot bin and it is having the required 16 bytes.
So binary format will only contains what is needed.
The actual opcodes in Elf is having a lot of extra content, including the opcode it has, the opcodes
or the machine instructions, but it also has a lot of additional thing.
So this is what now I need to add this content to the ad dot to the flash dot bin which we have.
So I will copy the flash dot bin which we created here.
And I will update.
Oh sorry.
I'll copy the flash bin here because add bin is only 16 bytes.
If I pass this to the chemo it will not accept this one.
It needs a 16 MB of file as a flash and it will give me an error.
Saying it device requires 16 MB, but you have only provided 512 bytes.
I don't know how it takes 512, but it is 16 bytes.
Okay, now how do I convert this to this?
I can use a command D and I can use a command.
Okay, this is fine.
So I can use something known as dx command.
And then.
I can do it.
So the input file is flash dot bin and sorry input file is add bin.
Or I just need to verify the command.
So input file is add dot bin and output file is flash dot bin.
And I do not need to I need to pass this option.
So it will overwrite only the content which is needed.
So I will run this one.
Now, if I see the hex dump of flash bin, the whatever we had is now present.
The initial 4x4 instructions are added and remaining are all zeros.
So what we have said is append this one and or do not.
I mean only overwrite this starting for 32 bits 16.
What is this, 16 bytes?
Right?
Uh, 16 is the characters here.
So only overwrite the 1616 characters and don't do any extra.
Now I can pass this to the flash bin.
And now if I say info registers, I can see the value of r zero is five, R one is four.
And this is what we have added I think.
And six add dot SR0 is five, r four and r two should have five plus four nine and r two is having nine.
So we we are able to get what we wanted right.
So we are we have uh written an assembly code.
And then we converted this assembly code into an op code using the required tools.
And then we executed this on the machine.
And then we have got the desired output.