home comics writing pictures archive about

2019-02-03 - In IL: Array Instructions

In IL

An array is a series of elements laid out continuously in memory with each element being accessible using its index value. The two key properties of an array are its bounds and its dimensions. Bounds indicate the lowest and highest possible index values while dimensions indicate how many index values are required.  For example a two-dimensional array could be used as a table with one index representing the rows and the other index representing the columns. The bounds would indicate how many rows and columns the table has. IL allows arrays with multiple dimensions and various bounds but treats one-dimensional arrays with a 0 for the lower bound as special. These arrays are referred to as vectors and there are special IL instructions for working with these types of arrays.

newarr (NEW ARRay)

Pops a integer off of the stack and creates a new array able to contain that many elements.

Instruction Description Binary Format
newarr <type> Create new array 0x8D <T>

ldlen (LoaD LENgth)

Pops an array off of the stack and pushes the length of the array onto the stack.

Instruction Description Binary Format
ldlen Length of array 0x8E

ldelema (LoaD ELEMent Address)

Pops an index value and an array off of the stack and pushes the address of the element of the array at the specified index onto the stack.

Instruction Description Binary Format
ldelema <type> load element address of specified type 0x8F <T>

ldelem (LoaD ELEMent)

Pops an index value and an array off of the stack and pushes the element of the array at the specified index onto the stack.

Instruction Description Binary Format
ldelem.i1 load 8 bit integer element 0x90
ldelem.u1 load 8 bit unsigned integer element 0x91
ldelem.i2 load 16 bit integer element 0x92
ldelem.u2 load 16 bit unsigned integer element 0x93
ldelem.i4 load 32 bit integer element 0x94
ldelem.u4 load 32 bit unsigned integer element 0x95
ldelem.i8 load 64 bit integer element 0x96
ldelem.u8 load 64 bit unsigned integer element 0x96
ldelem.i load native integer element 0x97
ldelem.r4 load 32 bit floating point element 0x98
ldelem.r8 load 64 bit floating point element 0x99
ldelem.ref load object element 0x9A
ldelem <type> load element of specified type 0xA3 <T>

stelem (SeT ELEMent)

Pops a value, an index value, and an array off of the stack and sets the element of the array at the specified index to the value.

Instruction Description Binary Format
stelem.i set native integer element 0x9B
stelem.i1 set 8 bit integer element 0x9C
stelem.i2 set 16 bit integer element 0x9D
stelem.i4 set 32 bit integer element 0x9E
stelem.i8 set 64 bit integer element 0x9F
stelem.r4 set 32 bit floating point element 0xA0
stelem.r8 set 64 bit floating point element 0xA1
stelem.ref set object element 0xA2
stelem<type> set element of specified type 0xA4<T>

Next time we'll look at some programs which use arrays.

Comments: