CIL stack exchange instruction

余生颓废 提交于 2019-12-21 04:11:51

问题


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


回答1:


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




回答2:


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




回答3:


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.




回答4:


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...



来源:https://stackoverflow.com/questions/191946/cil-stack-exchange-instruction

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!