⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vararg.il

📁 < Microsoft .NET IL汇编语言程序设计>>书上的源程序
💻 IL
字号:
.assembly extern mscorlib { }
.assembly Vararg {}
.module Vararg.exe

// Compute sum of undefined number of arguments
.method public static vararg unsigned int64 Sum(/* all arguments optional */)
{
    .locals init(valuetype [mscorlib]System.ArgIterator Args,
				unsigned int64 Sum,
				int32 NumArgs)
    ldc.i8 0
    stloc Sum	

    
    ldloca Args
    arglist // Create argument list structure 
    // Initialize ArgIterator with this structure:
    call instance void [mscorlib]System.ArgIterator::.ctor(
       value class [mscorlib]System.RuntimeArgumentHandle)
	 
    // Get the optional argument count:
    ldloca Args
    call instance int32 [mscorlib]System.ArgIterator::GetRemainingCount()
    stloc NumArgs

    // Main cycle:
  LOOP:
    ldloc NumArgs
    brfalse RETURN // if(NumArgs == 0) goto RETURN;

    // Get next argument:
    ldloca Args
    call instance typedref [mscorlib]System.ArgIterator::GetNextArg()

    // Interpret it as unsigned int64:
    refanyval [mscorlib]System.UInt64
    ldind.u8

    // Add it to Sum:
    ldloc Sum
    add
    stloc Sum // Sum += *((int64*)&next_arg)

    // Decrease NumArgs and go for next argument:
    ldloc NumArgs
    ldc.i4.m1
    add
    stloc NumArgs
    br LOOP

  RETURN:
    ldloc Sum
    ret
}

.method public static void Exec( )
{
    .entrypoint
	// Compute 123+234+345+567 and print result upon console
	ldc.i8 123
	ldc.i8 234
	ldc.i8 345
	ldc.i8 567
    	call vararg unsigned int64 Sum(..., unsigned int64, 
           unsigned int64, unsigned int64, unsigned int64)
	call void [mscorlib]System.Console::WriteLine(unsigned int64)
    ret
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -