In this video, we'll be writing an assembly program for some of an array.
The following code sums an array of bytes and stores the result in R3.
If you see in this code, uh, like we had the start and then this is the while loop.
But you have additional logic of uh eoa.
EOA is a label.
So you are loading this, uh, value of R0, a value of uh, e o a.
I mean, that is of e o in r0, which is end of the array.
Think of it as a end of array and then the address of R1, which is here in R1 address of a RR in R1
register.
And then you are moving the value zero in R3.
Then you are performing storing the value of R1 plus plus whatever.
This value, like R1 is ten in R2 and then you are adding zero plus ten, and then you are comparing.
If R1 is equals to r zero, then this is like the for loop logic or while loop logic.
And then you are going and continuing etc..
So if you see this code it introduces uh two new assembler directives.
One is a dot byte and dot align.
The byte directive is used to store uh, this in a consecutive bytes of memory.
So if you want to store this in a consecutive bytes in memory, you need to write dot byte.
Here is like one byte only.
So it is a read only array of bytes.
So similar to dot byte, you have two byte and four byte for storing 16 byte values and 32 bit values
respectively.
They follow this syntax like uh, dollar dot byte and you can store bytes in consecutive memory.
This is 4 to 16 bit and this is for 32 bit.
And you can uh.
You can have simple integers like this one.
Uh, or you can, if you want hexadecimal, then you need to assign uh, prefix of zero x.
Or if you are having binary, you can have zero be octal be prefixed by zero.
So some of the examples where you can see here uh dot byte and this is one byte, one byte in a consecutive
memory.
This will be stored in consecutive memories.
And uh, uh I can use uh, I if I want to find out the length of this one, I can use like this dot
byte and pattern is a current minus pattern.
And this is for Ascii and.
This is for hexadecimal.
This is a four byte and this is also Ascii.
And then you have one more which is align.
Uh, align is used to ARM requires that instructions to be present in 32 bit aligned memory locations.
Because here we are having three, uh, addresses with three values.
And this should start in 32 bit, uh, align memory location.
The address of the first byte of the four bytes in instruction should be multiple of four.
So for that, uh uh I am writing here align.
So it will add padding.
Uh it will insert the padding bytes.
This is required only when the data bytes or half words are inserted within the code.
Because we are inserting bytes and we are not inserting four bytes.
Right.
Inserting bytes or half.
And this will be only required because we are using bytes, not uh, four bytes.
Let's see.
I have copied this code already.
Uh, and if you remember the logic for building, we had the builder logic, right?
First we do, uh, convert this assembly to an object code.
So add.
Array, some O array some s, and then.
We use the linker and we inform the linker to generate an Elf file.
And Erasmo.
Now you can see the symbols using Ntlm command.
N m f n n array some dot elf.
And if you see, let's see, what is the address of, uh, entry?
Uh, is zero.
This is the first one.
Okay.
And then because we have added a RR uh, then comes for addresses, E0 is seven.
But if you see static site right.
Static site because you have added a line.
So a line added one byte of padding here.
So now what what I'll show you is like I'll remove that line and see what happens.
So I'll just say I'll comment this out.
So this is commented.
Now I'll compile this one misaligned band's destination.
Let's see what is happening.
Okay, I'll just remove this one.
And now I'll compile.
It's coming at the line number two.
Branch start.
Because it is having this EOA thing.
So it is giving this error.
I will comment this one and I will say like this.
Misaligned branch.
Destination.
So yeah, if you're seeing the message right, it is saying misaligned branch destination.
That's because we have removed align right.
Because we have removed align.
We are getting this message.
So now align is needed for us AOA and AOA align is needed.
So because I am expecting that, uh, instructions should be at the 32 bit, uh, location.
Now we are not getting any error.
Now, let's, uh, convert this one.
Now everything is as expected because we have removed this and there was not not proper alignment.
So you get like misaligned branch designation.
Now.
We will copy the binary file.
I will generate a binary using obj copy.
Let's do the hex dump.
So this is the file we have résum dot bin just having 27 bytes of information.
Now we will run this one.
So again, we need to copy this and generate a 16 MB of flash memory.
And then.
We can give our bin file as input and ask it to overwrite in the flash bin.
I can just say con equals to no trunk.
Now it has, uh, if you see hexdump F and C plus dot bin.
So whatever is our content till here or till here is added here as I mean, here it is added now I can
start my chemo emulator.
And I can verify whether it is working or not.
So info registers are 0 or 2.
So I'll just close this one and I'll show you the code.
So.
So first, uh, if you see, uh, the value, what will be the output?
Ten plus 20, 30 plus 25, 65.
So 65 is hexadecimal of 37.
So 16 is a 48.
So sorry this is not 6550, 45 plus 55.
So 55 is uh, 37, 16th is a 48 plus seven is 55.
So we are getting the correct output.
We are storing the result in R3, and R3 is having the correct output.
And coming to next, uh, what is the value of r0 and r1 and r0 and r1 are having seven because EOA
it will continue until uh uh r1 is incremented until it reaches EOA and both are having the correct
value.
Uh.
Okay.
Yeah.
And R2 is having 19 which is 16 plus nine is 25.
So it is having the value of 25 here.
So yeah.
So in this example we have seen how can we perform sum of an array.
And we have seen two directives.
One is dot align which is used to align the instruction.
Add a necessary padding and dot byte to store this in a consecutive memory locations.