Is there CIL instruction to exchange the first two elements in the stack?
+4
A:
There is no single instruction exchange. However, using stloc, pop, and ldloc, you should be able to accomplish your exchange.
sixlettervariables
2008-10-10 15:49:26
+1
A:
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.
Chris Charabaruk
2008-10-10 15:50:07
A:
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...
Will
2008-10-10 16:50:08
A:
No. The only way to swap elements is to pop the top two elements to locals, then push them in reverse order.
Nick Johnson
2008-10-10 21:28:53