C#代码编译成机器指令码
看一看这个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
nop
add rsp, 8
ret
Program:Square(int):int:
mov eax, edi
imul eax, edi
ret
这是不是很有趣?编译器的优化使到这种结果变成有可能。
看来没多少人对这个课题感兴趣,还好我理解。:L:lol
页:
[1]