MSIL指令参考
MSIL指令参考
来源 https://www.cnblogs.com/lbq1221119/archive/2007/10/17/926919.html
ILOPC指令参考 https://docs.microsoft.com/zh-cn/dotnet/api/system.reflection.metadata.ilopcodeextensions?view=net-5.0
Note that there are special short (and hence more efficient) encodings for the integers -128 through 127, and especially short encodings for -1 through 8. All short encodings push 4 byte integers on the stack. Longer encodings are used for 8 byte integers and 4 and 8 byte floating-point numbers, as well as 4-byte values that do not fit in the short forms. There are three ways to push an 8 byte integer constant onto the stack.
参见:
http://msdn2.microsoft.com/en-us/library/system.reflection.emit.opcodes.ldc_i4(vs.71).aspx
ldc指令的语法如下:
ldc.type value
ldc.i4.number
ldc.i4.s number
在第一条语法中,ldc指令加载一个指定类型的常量到stack.
在第二条语法的指令当中,ldc指令更加有效.它传输一个整型值-1以及0到8之间的整数给计算堆栈.当我们传输-1到计算堆栈的时候,这条ldc的语法指令又进一步演变成为ldc.i4.ml.
这里,截取ECMA的C#标准里面关于这个指令的完整参考:
Ref:
引用部分来自ECMA关于CLI部分的说明.如果安装了.Net Framework SDK1.1的话,可以在这里找到:
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Tool Developers Guide\docs\Partition III CIL.doc
Format |
Assembly Format |
Description |
20 <int32> |
ldc.i4 num |
Push num of type int32 onto the stack as int32. |
21 <int64> |
ldc.i8 num |
Push num of type int64 onto the stack as int64. |
22 <float32> |
ldc.r4 num |
Push num of type float32 onto the stack as F. |
23 <float64> |
ldc.r8 num |
Push num of type float64 onto the stack as F. |
16 |
ldc.i4.0 |
Push 0 onto the stack as int32. |
17 |
ldc.i4.1 |
Push 1 onto the stack as int32. |
1E |
ldc.i4.8 |
Push 8 onto the stack as int32. |
15 |
ldc.i4.m1 |
Push -1 onto the stack as int32. |
15 |
ldc.i4.M1 |
Push -1 of type int32 onto the stack as int32 (alias). |
1F <int8> |
ldc.i4.s num |
Push num onto the stack as int32, short form. |
Stack里面的传输方向:
… --> …, num
Description:
The ldc num instruction pushes number num or some constant onto the stack. There are special short encodings for the integers –128 through 127 (with especially short encodings for –1 through 8). All short encodings push 4-byte integers on the stack. Longer encodings are used for 8-byte integers and 4- and 8-byte floating-point numbers, as well as 4-byte values that do not fit in the short forms.
There are three ways to push an 8-byte integer constant onto the stack
1. For constants that shall be expressed in more than 32 bits, use the ldc.i8 instruction.
2. For constants that require 9–32 bits, use the ldc.i4 instruction followed by a conv.i8.
3. For constants that can be expressed in 8 or fewer bits, use a short form instruction followed by a conv.i8.
There is no way to express a floating-point constant that has a larger range or greater precision than a 64-bit IEC 60559:1989 number, since these representations are not portable across architectures.
Ref:引用结束
从这里,我们可以看到ldc指令极其参数的完整使用说明.
============= End
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
2017-11-18 Win10 安装 Linux 子系统