Skip to content

Latest commit

 

History

History
39 lines (21 loc) · 2.06 KB

iii.4.13-ldobj.md

File metadata and controls

39 lines (21 loc) · 2.06 KB

III.4.13 ldobj – copy a value from an address to the stack

Format Assembly Format Description
71 <\T> ldobj typeTok Copy the value stored at_address src to the stack.

Stack Transition:

…, src → …, val

Description:

The ldobj instruction copies a value to the evaluation stack. typeTok is a metadata token (a typedef, typeref, or typespec). src is an unmanaged pointer (native int), or a managed pointer (&). If typeTok is not a generic parameter and either a reference type or a built-in value class, then the ldind instruction provides a shorthand for the ldobj instruction.

[Rationale: The ldobj instruction can be used to pass a value type as an argument. end rationale]

If required values are converted to the representation of the intermediate typeI.8.7) of typeTok when loaded onto the stack (§III.1.1.1).

[Note: That is integer values of less than 4 bytes, a boolean or a character are converted to 4 bytes by sign or zero-extension as appropriate. Floating-point values are converted to F type. end note]

The operation of the ldobj instruction can be altered by an immediately preceding volatile. or unaligned. prefix instruction.

Exceptions:

System.NullReferenceException can be thrown if an invalid address is detected.

System.TypeLoadException is thrown if typeTok cannot be found. This is typically detected when CIL is converted to native code rather than at runtime.

Correctness:

typeTok shall be a valid typedef, typeref, or typespec metadata token.

[Note: Unlike the ldind instruction a ldobj instruction can be used with a generic parameter type. end note]

Verifiability:

The tracked type of the source value on top of the stack shall be a managed pointer to some type srcType, and srcType shall be assignable-to the type typeTok.

Verification tracks the type of the result val as the intermediate type of typeTok.