CIL stack exchange instruction

后端 未结 4 2190
走了就别回头了
走了就别回头了 2021-02-14 15:03

Is there a CIL instruction to exchange the first two elements in the stack?

相关标签:
4条回答
  • 2021-02-14 15:29

    For future reference, you can create an assembly that does what you want to learn the IL for, then view the assembly in Reflector. You can select the language you wish the code to be in, and IL is one of the options. I did this when trying to figure out how to code a dynamic method...

    0 讨论(0)
  • 2021-02-14 15:32

    No. The only way to swap elements is to pop the top two elements to locals, then push them in reverse order.

    0 讨论(0)
  • 2021-02-14 15:34

    Looking at a list of CIL instructions there doesn't appear to be a single instruction that exchanges the two elements at the top of the stack. You'll have to do it the old pop/push way.

    0 讨论(0)
  • 2021-02-14 15:38

    There is no single instruction exchange. However, using stloc, pop, and ldloc, you should be able to accomplish your exchange.

    0 讨论(0)
提交回复
热议问题