CHAPTER 18 UNDERSTANDING CIL AND THE ROLE OF DYNAMIC ASSEMBLIES
{
instance void .ctor(int32 c, string p) cil managed
.maxstack
8
// Load first arg onto the stack and call base class ctor.
ldarg.0 // "this" object, not the int32!
call instance void [mscorlib]System.Object::.ctor()
// Now load first and second args onto the stack.
ldarg.0 // "this" object
ldarg.1 // int32 arg
// Store topmost stack (int 32) member in currSpeed field.
stfld int32 CILCars.CILCar::currSpeed
}
}
// Load string arg and store in petName field.
ldarg.0 // "this" object
ldarg.2 // string arg
stfld string CILCars.CILCar::petName
ret
}
Keeping in mind that the real first argument for any nonstatic member is the current object
reference, the first block of CIL simply loads the object reference and calls the base class constructor.
Next, you push the incoming constructor arguments onto the stack and store them into the type’s field
data using the stfld (store in field) opcode.
Now let’s implement the second type in this namespace: CILCarInfo. The meat of the type is found
within the static Display() method. In a nutshell, the role of this method is to take the incoming CILCar
parameter, extract the values of its field data, and display it in a Windows Forms message box. Here is
the complete implementation of CILCarInfo (which should be defined within the CILCars namespace)
with analysis to follow:
.class public auto ansi beforefieldinit CILCarInfo
extends [mscorlib]System.Object
{
.method public hidebysig static voi