Skip to content

Latest commit

 

History

History
43 lines (23 loc) · 1.88 KB

iii.4.26-stelem.md

File metadata and controls

43 lines (23 loc) · 1.88 KB

III.4.26 stelem – store element to array

Format Assembly Format Description
A4 <T> stelem typeTok Replace array element at index with the value on the stack

Stack Transition:

…, array, index, value, → …

Description:

The stelem instruction replaces the value of the element with zero-based index index (of type native int or int32) in the one-dimensional array array, with value. Arrays are objects and hence are represented by a value of type O. The type of value must be array-element-compatible-with typeTok in the instruction.

Storing into arrays that hold values smaller than 4 bytes whose intermediate type is int32 truncates the value as it moves from the stack to the array. Floating-point values are rounded from their native size (type F) to the size associated with the array. (See §III.1.1.1, Numeric data types.)

[Note: For one-dimensional arrays that aren't zero-based and for multidimensional arrays, the array class provides a StoreElement method. end note]

Exceptions:

System.NullReferenceException is thrown if array is null.

System.IndexOutOfRangeException is thrown if index is larger than the bound of array.

System.ArrayTypeMismatchException is thrown if array doesn't hold elements of the required type.

Correctness:

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

array shall be null or a single dimensional array.

Verifiability:

Verification requires that:

  • the tracked type of array is T[], for some T;

  • the tracked type of value is array-element-compatible-withI.8.7.1) typeTok;

  • typeTok is array-element-compatible-with T; and

  • the type of index is int32 or native int.