CHAPTER 18 UNDERSTANDING CIL AND THE ROLE OF DYNAMIC ASSEMBLIES
beq, bgt, ble, blt, switch
These CIL opcodes (in addition to many other related opcodes) are used to
control branching logic within a method. For example:
beq: Break to code label if equal
bgt: Break to code label if greater than
ble: Break to code label if less than or equal to
blt: Break to code label if less than
All of the branch-centric opcodes require that you specify a CIL code label
to jump to if the result of the test is true.
call
This CIL opcode is used to call a member on a given type.
newarr, newobj
These CIL opcodes allow you to allocate a new array or new object type
into memory (respectively).
The next broad category of CIL opcodes (a subset of which is shown in Table 18-6) are used to load
(push) arguments onto the virtual execution stack. Note how these load-specific opcodes take an ld
(load) prefix.
Table 18-6. The Primary Stack-Centric Opcodes of CIL
Opcode
Meaning in Life
ldarg (with numerous variations)
Loads a method’s argument onto the stack. In addition to the
general ldarg (which works in conjunction with a given index
that identifies the argument), there are numerous other variations.
For example, ldarg opcodes that have a numerical suffix
(ldarg_0) hard-code which argument to load. As well, variations
of the ldarg opcode allow you to hard-code the data type using
the CIL constant notation shown in Table 18-4 (ldarg_I4, for an
int32), as well as the data type and value (ldarg_I4_5, to load an
int32 with the value of 5).
ldc (with numerous variations)
Loads a constant value onto the stack.
ldfld (with numerous variations)
Loads the value of an instance-level field onto the stack.
ldloc (with numerous variations)
Loads the value of a local variable onto the stack.
ldobj
Obtains all the values gathered by a heap-based object and
places them on the stack.
ldstr
Loads a string value onto the stack.
In addition to the set of load-specific opcodes, CIL provides numerous opcodes that explicitly pop
the topmost value off the stack. As shown over the first few examples in this chapter, popping a value off
674