Modest Introduction To IL Assembly Language
To compile and run the code you must have installed Microsoft .NET Framework Beta 2 available for download fromhttp://msdn.Microsoft.com.
Since I received copy of Visual Studio .NET Beta 2 and did not manage to find”ILAssemblyLanguageProgrammersReference.doc” which was included in beta 1 I decided to share my experience withother assembly enthusiasts. Documents for somebody interested in intermediate language could be find in :”C:\Program Files\Microsoft.NET\FrameworkSDK\Tool Developers Guide\docs”. Typically work with assembler is fromcommand line and using notepad. To open command line in some directory I’m creating registry entry (key) in”HKEY_CLASSES_ROOT\Folder\shell” called CmdLine and again new entry in CmdLine called command where we arechanging (Default) to string value REG_SZ “cmd.exe %1″. In that way we are opening command line using contextmenu (right click on folder icon and select CmdLine). Also it comes handy to create shortcut to NOTEPAD.EXE andildasm.exe in “C:\Documents and Settings\whatever your name is\SendTo” so that you can send .il files to notepadand .exe files to disassembler.
First we will write client and from client send string to ArgIn.dll which will show our string in message box. Copyfollowing, paste it in notepad and save as client.il
.assembly extern mscorlib{}
.assembly extern ArgIn{}
.assembly go{}
.method public static void GO2() cil managed
//any name starting with letter is ok
{
.entrypoint //must
.maxstack 1
//you can safely comment out .maxstack 1 or
//set it on 2 but if it is insufficient results in run-time error
.locals ([0] class [ArgIn]ArgIn.Class1 q)
//.locals [init] ( <localssignature> )
//Defines a set of local variables for this method.
ldstr “Hello from client”
//72 <t> ldstr string push a string object for the literal string
newobj instance void [ArgIn]ArgIn.Class1::.ctor(string)
//73 <t> newobj ctor allocate an uninitialized object and call ctor
stloc.0
//0A stloc.0 Pop value from stack into local variable 0.
//pop will also do here (we won’t use it again)
ret //return is a must
}
</t></t></localssignature>
Do not compile yet, first we must compile library. Following is what we are going to compile to ArgIn.dll :
Continues…
Pages: 1 2












No comments yet... Be the first to leave a reply!