In this example we are calculating the length of the string.
So if you see this is a code and if uh comparing to the previous code, again we have two more new assembler
directives.
One is Ascii z and other is not equal.
We have already seen what is dot align in the previous video.
So let's see what is this Ascii z and as equal I aq.
So ascii z is like uh uh ask is a directive accepts string length string literals as arguments, string
literal, or a sequence character in double quotes.
So if you want to have something in double quotes like this, I can use ascii z.
I can also use dot byte like uh, we have seen in the previous example, but I need to have in a separated
by characters, uh, single character separated by comma.
But with ascii z, I can keep everything in a double quotes and it will store it.
Uh, so ask is it is for that?
So and uh, this is again assembled into consecutive memory locations and assembler automatically inserts
a null character after each string.
You have one more dollar Ascii, uh, but dollar Ascii in if you use dollar as Ascii assembler does
not insert a null character after each string.
Then there is one more directive here in the code which is dot equal.
Equal is like uh, it is used for a symbol table.
So assembler maintains something called as a symbol table which we are seeing using Ntlm command.
We are listing the name label name and the address.
So symbol table maps label names to addresses.
And whenever a assembler encounters a label definition, assembler makes an entry in the symbol table.
And uh, whenever a symbol assembler encounters a label reference like the label definition is like
this one, this is a label definition.
Uh, this is a label reference.
Okay.
Whenever assembler encounters a label reference, it replaces the label by the corresponding address
from the symbol table.
And when we have this dot equals two, we can manually insert our own entries in the symbol table because
this is not a label.
So when is the assembler adding a label definition in the symbol table whenever it sees this definition.
But we don't have a definition here.
And we want to add we want to add a new symbol entry in the symbol table I can use dollar equal to.
So the syntax is equal to name and expression name is a symbol.
Name and expression can be a the same like address or whatever the expression we have seen for the byte
directive.
And this will not allocate any extra memory like, uh, the dollar by directory.
Well.
So if you look in the code, uh, we have, uh, specifying there's a dollar text text segment and we
are starting branch to start.
And we are loading the value of uh, str in our zero register.
And we are moving R1 as the value of zero in R1.
So finally the result will be stored in R1.
And then we are loading the value of uh the actual value of r zero.
And we are loading it into R2 and then we are adding r1, R1.
Again incrementing the value.
So this is a increment operator until this becomes r two becomes null.
So we go one by one one by one until we get a null character.
And then we skip this loop.
And then we decrement it by one and we print the result.
So the output if we compile this one should be uh 23456789 1011.
So let's see the output.
So again uh, let's use a build instructions which we have.
So um none Abi first convert this into opcode string length.
Oh.
Object code string length s.
It's not S, it's asm.
I can use either ASM or I can use s.
Uh.
It's fine.
Um.
None ld t text 0X0, f and zero and string length dll f string length oh.
And I can check the symbol table now.
And string length.
E.L.F.
I will print the code for us to understand.
So if you see here, uh, there is a null which we have added in the symbol table is assigned with the
value zero okay.
Null is assigned with the value zero.
And.
Start is assigned with the value ten because you have a string here.
STR is assigned the value four and then ten means it is 16.
This hexadecimal.
So whatever is this is a place in the consecutive memory locations.
If I do hex dump also on the binary code.
You will be seeing Hello world stored in the consecutive memory location.
Now.
Let's generate the.
Object binary file.
And if you do a xtum, you will be seeing the actual contents.
So hello world is stored first.
And if you see this code now, if you see the NM.
Let's see.
NM only works for your example information.
It does not work on bin files.
It only works on.
It only works on the.
L file.
So this file format is not recognized for NM.
It only works on the bin files.
So.
Here it is a null is there and starts with four.
Hello world starts at the next address and then this consecutive memory location.
Now let's run the chemo.
And for that again we need, uh, d d uh.
We need to create our own flash location, and the input file equals to.
Uh, input file is now string length dot bin and output file.
Again.
Just change this to.
It needs to just append on whatever is existing.
And now it has copied the 52 bytes.
Now I can use my chemo command and I can check the registers.
And the value is b.
B is like 11.
So it's, it has, uh, given us the expected output.
The Hello World is having 11 characters and then it gave us a expected output.