How does the .NET IL .maxstack directive work?

后端 未结 3 2103
清酒与你
清酒与你 2021-01-01 11:10

I\'d like to know how does .maxstack really work. I know it doesn\'t have to do with the actual size of the types you are declaring but with the number of them. My questions

3条回答
  •  不知归路
    2021-01-01 11:43

    You can refer to the following and the ECMA STANDARD to get a better understanding:

    void  msd(string a,
      string b,
      string c,
      string d,
      string e)
      {
      Console.WriteLine(a);
    }
    
    msd("a","b","c","d","e");
    

    When I run ildasm.exe I got this:

    {
      .entrypoint
      // Code size       40 (0x28)
      .maxstack  8
      IL_0000:  nop
      IL_0001:  nop
      IL_0002:  ldstr      "a"
      IL_0007:  ldstr      "b"
      IL_000c:  ldstr      "c"
      IL_0011:  ldstr      "d"
      IL_0016:  ldstr      "e"
      IL_001b:  call       void sf.Program::'
    g__msd|0_0'(string, string, string, string, string) IL_0020: nop IL_0021: call string [mscorlib]System.Console::ReadLine() IL_0026: pop IL_0027: ret } // end of method Program::Main

    from the above. I found the max stakc value which isn't determined by the push & pop instructions.

    I didn't know what the real stack number values are. So, I reference the ildasm disassembly code to determine the real max stack value.

提交回复
热议问题