马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
看一看这个C#源代码,呼叫Square()函数:
- using System;
- class Program
- {
- static int Square(int num) => num * num;
- static void Main(string[] args){
- Console.WriteLine(Square(8));
- }
- }
复制代码
可是最终的机器指令码,编译器其实没有呼叫Square()函数,而是直接计算8x8的结果(64):
- Program:.ctor():this:
- ret
- Program:Main(System.String[]):
- push rax
- mov edi, 64
- call [System.Console:WriteLine(int)]
- nop
- add rsp, 8
- ret
- Program:Square(int):int:
- mov eax, edi
- imul eax, edi
- ret
复制代码
这是不是很有趣?编译器的优化使到这种结果变成有可能。
|