First of all, lets create simple application to debug. Set a break point and start application.
using System;

namespace ConsoleApplication
    class Program
        static void Main()
            var a = 3;
            var b = 2;
            var result = a + b;
            Console.WriteLine("Result: {0}", result);

When break point is hit, open Debug > Windows > Disassembly. A new window will open with C# mixed with assembly and with break point. You can use Step Over and Step Out to move between assembly instructions.
--- c:\Users\s\Documents\Visual Studio 2013\Projects\ConsoleApplication\ConsoleApplication\Program.cs 
     8:         {
00B22E9A  in          al,dx  
00B22E9B  push        edi  
00B22E9C  push        esi  
00B22E9D  push        ebx  
00B22E9E  sub         esp,44h  
00B22EA1  lea         edi,[ebp-50h]  
00B22EA4  mov         ecx,11h  
00B22EA9  xor         eax,eax  
00B22EAB  rep stos    dword ptr es:[edi]  
00B22EAD  cmp         dword ptr ds:[0A4C504h],0  
00B22EB4  je          00B22EBB  
00B22EB6  call        727D38A2  
00B22EBB  xor         edx,edx  
00B22EBD  mov         dword ptr [ebp-44h],edx  
00B22EC0  xor         edx,edx  
00B22EC2  mov         dword ptr [ebp-40h],edx  
00B22EC5  xor         edx,edx  
00B22EC7  mov         dword ptr [ebp-3Ch],edx  
00B22ECA  nop  
     9:             var a = 3;
00B22ECB  mov         dword ptr [ebp-3Ch],3  
    10:             var b = 2;
00B22ED2  mov         dword ptr [ebp-40h],2  
    11:             var result = a + b;
00B22ED9  mov         eax,dword ptr [ebp-3Ch]  
00B22EDC  add         eax,dword ptr [ebp-40h]  
00B22EDF  mov         dword ptr [ebp-44h],eax  
    12:             Console.WriteLine("Result: {0}", result);
00B22EE2  mov         ecx,5BC6FE38h  
00B22EE7  call        00A330F4  
00B22EEC  mov         dword ptr [ebp-48h],eax  
00B22EEF  mov         eax,dword ptr ds:[34F21CCh]  
00B22EF5  mov         dword ptr [ebp-4Ch],eax  
00B22EF8  mov         eax,dword ptr [ebp-48h]  
00B22EFB  mov         edx,dword ptr [ebp-44h]  
00B22EFE  mov         dword ptr [eax+4],edx  
00B22F01  mov         eax,dword ptr [ebp-48h]  
00B22F04  mov         dword ptr [ebp-50h],eax  
00B22F07  mov         ecx,dword ptr [ebp-4Ch]  
00B22F0A  mov         edx,dword ptr [ebp-50h]  
00B22F0D  call        5BBEC704  
00B22F12  nop  
    13:         }
00B22F13  nop  
00B22F14  lea         esp,[ebp-0Ch]  
00B22F17  pop         ebx  
00B22F18  pop         esi  
00B22F19  pop         edi  
00B22F1A  pop         ebp  
00B22F1B  ret  
--- No source file -------------------------------------------------------------
Some comments on marked lines.

Variable initialization, with default values:
  • 16 - result
  • 18 - b
  • 20 - a
Initial values:
  • 23 - set value to a
  • 25 - set value to b
Perform a and b addition:
  • 27 - load b
  • 28 - add a to previously loaded value
  • 29 - store output to result variable
Console.WriteLine execution:
  • 34 - load "Result :{0}" string from 34F21CCh address to ebp-48h registry
  • 36 - load "Result :{0}" string from ebp-48h
  • 37 - load result variable
  • 43 - invoke Console.WriteLine function, and pass all loaded variables
And that's where my assembly knowledge ends :)


Comments are closed