Skip to content

Latest commit

 

History

History
30 lines (17 loc) · 2.38 KB

iii.3.44-ldloca-length.md

File metadata and controls

30 lines (17 loc) · 2.38 KB

III.3.44 ldloca.<length> – load local variable address

Format Assembly Format Description
FE 0D <unsigned int16> ldloca indx Load address of local variable with index indx.
12 <unsigned int8> ldloca.s indx Load address of local variable with index indx, short form.

Stack Transition:

… → …, address

Description:

The ldloca instruction pushes the address of the local variable number indx onto the stack, where local variables are numbered 0 onwards. The value pushed on the stack is already aligned correctly for use with instructions like ldind and stind. The result is a managed pointer (type &). The ldloca.s instruction provides an efficient encoding for use with the local variables 0–255. (Local variables that are the subject of ldloca shall be aligned as described in the ldind instruction, since the address obtained by ldloca can be used as an argument to ldind.)

Exceptions:

System.VerificationException is thrown if the localsinit bit for this method has not been set, and the assembly containing this method has not been granted System.Security.Permissions.SecurityPermission.SkipVerification (and the CIL does not perform automatic definite-assignment analysis)

Correctness:

Correct CIL ensures that indx is a valid local index.

For the ldloca indx instruction, indx shall lie in the range 0–65534 inclusive (specifically, 65535 is not valid).

[Rationale: The reason for excluding 65535 is pragmatic: likely implementations will use a 2-byte integer to track both a local's index, as well as the total number of locals for a given method. If an index of 65535 had been made valid, it would require a wider integer to track the number of locals in such a method. end rationale]

Verifiability:

Verification (§III.1.8) tracks the type of the value loaded onto the stack as a managed pointer to the verification type (§I.8.7) of the local variable. For verifiable code, this instruction shall guarantee that it is not loading the address of an uninitialized value – whether that initialization is done explicitly by having set the localsinit bit for the method, or by previous instructions (where the CLI performs definite-assignment analysis)