Groups | Blog | Home
all groups > dotnet clr > january 2005 >

dotnet clr : uniqueness of id's in .locals init



u_int32_t
1/31/2005 12:18:30 AM
I have come across an example where the following compiles in ms.net:

..locals init([0]unsigned int8 _loop_param,
[1]unsigned int8 _loop_limit,
[2]unsigned int8 _loop_param,
[3]unsigned int8 _loop_limit,
[4]unsigned int8 _loop_param,
[5]unsigned int8 _loop_limit,
....)

Do id's in .locals init(...) have to be unique?

Also, what is the meaning of the [n] prefix?

I can't locate this information in the standards so any help would be
appreciated.

u_int32_t
1/31/2005 3:14:15 PM
[quoted text, click to view]

Oddly enough try the following:

..assembly extern mscorlib { }
..assembly hello { }
..method static public void main() cil managed
{ .maxstack 3
.entrypoint
.locals init([0]unsigned int8 _a,
[1]unsigned int8 _a)
ldloca 0
ldloca 1
ldstr "Hello world!"
call void [mscorlib]System.Console::WriteLine(class System.String)
ret
}

The above will work successfully. The following will not (for obvious
reasons):

..assembly extern mscorlib { }
..assembly hello { }
..method static public void main() cil managed
{ .maxstack 3
.entrypoint
.locals init([0]unsigned int8 _a,
[1]unsigned int8 _a)
ldloca _a
ldloca _a
ldstr "Hello world!"
call void [mscorlib]System.Console::WriteLine(class System.String)
ret
}
Mattias Sjögren
1/31/2005 9:51:31 PM

[quoted text, click to view]

Do you mean the variable names? I don't know if ILASM will accept
duplicates, but for the CLR it certainly doesn't matter. In fact, the
names of locals aren't stored in the compiled executable, only in
debug symbols.


[quoted text, click to view]

Mostly informational, but you can also use it give different names to
the same stack slot, e.g. if you want to reuse the same slot in
different scopes.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Holger Grund
2/5/2005 12:32:28 AM
[quoted text, click to view]
[..]
In fact, I think both are invalid programs. You still have to items
on the stack on function exit. IIRC that's invalid. You should
need to add two pops in front of the ret.

What does ildasm say for the files? Peverify might give useful
output, too. With the stack issue fixed, the program should
be verifiable.

-hg

u_int32_t
2/5/2005 12:34:52 AM
[quoted text, click to view]

Yeah true, I'm just starting to learn IL. Don't have a book yet so I
apologize. I'm running off of the standard. This is another example:

..assembly extern mscorlib {}
..assembly test {}
..method static public void main() cil managed
{ .entrypoint
.maxstack 8
.locals init (unsigned int8 x, unsigned int8 x)

// probably ends up being stored in 0
ldc.i4.7
stloc.s x

// stores 8 into 1
ldc.i4.8
stloc.1

ldstr "0: "
call void [mscorlib]System.Console::Write(string)

ldloc.0
call void [mscorlib]System.Console::WriteLine(int32)

ldstr "1: "
call void [mscorlib]System.Console::Write(string)

ldloc.1
call void [mscorlib]System.Console::WriteLine(int32)
ret
}

The output is 7 and 8.

Should I pop after a call as well? The examples in the standard don't
Mattias Sjögren
2/5/2005 12:09:54 PM
[quoted text, click to view]

No, since the method return type is void.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button