There are some loading instructions in CIL such as ldc.i4.0, ldc.i4.1, ldc.i4.2, ldc.i4.3 …
I wonder, is it possible to use ldc.i4 1 instead of ldc.i4.1 or ldc.i4 5 instead of ldc.i4.5?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, it is entirely legal to use
ldc.i4 1in place ofldc.i4.1. The single-byte op-codes are given for efficiency and brevity in the most common scenarios. In particular, all thoseldarg.0(1 byte) would quickly add up to significantly increase the size of your assembly if they wereldarg 0(3 bytes), as would theldc.i4.1in things likei++;ldc.i4 1is 5 bytes instead of 1.You are not obliged to use them. I would actually expect (untested) the JIT to spot the more verbose usage and treat it the same anyway, although it would not be required to do so.
Personally, when I’m doing “emit” or similar, I just use a utility method that emits the most appropriate code(s) for any given value / local / argument / etc.