Created
February 17, 2020 09:21
-
-
Save fredeil/00f7dbad4c1c407e005238c85eeb65de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public static int[] Reverse(int[] values) | |
{ | |
int N = values.Length; | |
for (var i = 0; i < N; i++) | |
{ | |
values[i] = values[N-i]; | |
values[N-i] = values[i]; | |
} | |
return values; | |
} | |
public static void Main() | |
{ | |
int[] values = new [] {1,2,3,4}; | |
int[] reverse = Reverse(values); | |
for (var i = 0; i < values.Length; i++) | |
{ | |
Console.WriteLine($"Reverse: {values[i]}, {reverse[i]}"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.class private auto ansi '<Module>' | |
{ | |
} // end of class <Module> | |
.class public auto ansi beforefieldinit Program | |
extends [System.Private.CoreLib]System.Object | |
{ | |
// Methods | |
.method public hidebysig static | |
int32[] Reverse ( | |
int32[] values | |
) cil managed | |
{ | |
// Method begins at RVA 0x2050 | |
// Code size 45 (0x2d) | |
.maxstack 5 | |
.locals init ( | |
[0] int32, | |
[1] int32, | |
[2] bool, | |
[3] int32[] | |
) | |
IL_0000: nop | |
IL_0001: ldarg.0 | |
IL_0002: ldlen | |
IL_0003: conv.i4 | |
IL_0004: stloc.0 | |
IL_0005: ldc.i4.0 | |
IL_0006: stloc.1 | |
// sequence point: hidden | |
IL_0007: br.s IL_001f | |
// loop start (head: IL_001f) | |
IL_0009: nop | |
IL_000a: ldarg.0 | |
IL_000b: ldloc.1 | |
IL_000c: ldarg.0 | |
IL_000d: ldloc.0 | |
IL_000e: ldloc.1 | |
IL_000f: sub | |
IL_0010: ldelem.i4 | |
IL_0011: stelem.i4 | |
IL_0012: ldarg.0 | |
IL_0013: ldloc.0 | |
IL_0014: ldloc.1 | |
IL_0015: sub | |
IL_0016: ldarg.0 | |
IL_0017: ldloc.1 | |
IL_0018: ldelem.i4 | |
IL_0019: stelem.i4 | |
IL_001a: nop | |
IL_001b: ldloc.1 | |
IL_001c: ldc.i4.1 | |
IL_001d: add | |
IL_001e: stloc.1 | |
IL_001f: ldloc.1 | |
IL_0020: ldloc.0 | |
IL_0021: clt | |
IL_0023: stloc.2 | |
// sequence point: hidden | |
IL_0024: ldloc.2 | |
IL_0025: brtrue.s IL_0009 | |
// end loop | |
IL_0027: ldarg.0 | |
IL_0028: stloc.3 | |
IL_0029: br.s IL_002b | |
IL_002b: ldloc.3 | |
IL_002c: ret | |
} // end of method Program::Reverse | |
.method public hidebysig static | |
void Main () cil managed | |
{ | |
// Method begins at RVA 0x208c | |
// Code size 79 (0x4f) | |
.maxstack 4 | |
.locals init ( | |
[0] int32[], | |
[1] int32[], | |
[2] int32, | |
[3] bool | |
) | |
IL_0000: nop | |
IL_0001: ldc.i4.4 | |
IL_0002: newarr [System.Private.CoreLib]System.Int32 | |
IL_0007: dup | |
IL_0008: ldtoken field valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=16' '<PrivateImplementationDetails>'::'1456763F890A84558F99AFA687C36B9037697848' | |
IL_000d: call void [System.Private.CoreLib]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [System.Private.CoreLib]System.Array, valuetype [System.Private.CoreLib]System.RuntimeFieldHandle) | |
IL_0012: stloc.0 | |
IL_0013: ldloc.0 | |
IL_0014: call int32[] Program::Reverse(int32[]) | |
IL_0019: stloc.1 | |
IL_001a: ldc.i4.0 | |
IL_001b: stloc.2 | |
// sequence point: hidden | |
IL_001c: br.s IL_0044 | |
// loop start (head: IL_0044) | |
IL_001e: nop | |
IL_001f: ldstr "Reverse: {0}, {1}" | |
IL_0024: ldloc.0 | |
IL_0025: ldloc.2 | |
IL_0026: ldelem.i4 | |
IL_0027: box [System.Private.CoreLib]System.Int32 | |
IL_002c: ldloc.1 | |
IL_002d: ldloc.2 | |
IL_002e: ldelem.i4 | |
IL_002f: box [System.Private.CoreLib]System.Int32 | |
IL_0034: call string [System.Private.CoreLib]System.String::Format(string, object, object) | |
IL_0039: call void [System.Console]System.Console::WriteLine(string) | |
IL_003e: nop | |
IL_003f: nop | |
IL_0040: ldloc.2 | |
IL_0041: ldc.i4.1 | |
IL_0042: add | |
IL_0043: stloc.2 | |
IL_0044: ldloc.2 | |
IL_0045: ldloc.0 | |
IL_0046: ldlen | |
IL_0047: conv.i4 | |
IL_0048: clt | |
IL_004a: stloc.3 | |
// sequence point: hidden | |
IL_004b: ldloc.3 | |
IL_004c: brtrue.s IL_001e | |
// end loop | |
IL_004e: ret | |
} // end of method Program::Main | |
.method public hidebysig specialname rtspecialname | |
instance void .ctor () cil managed | |
{ | |
// Method begins at RVA 0x20e7 | |
// Code size 8 (0x8) | |
.maxstack 8 | |
IL_0000: ldarg.0 | |
IL_0001: call instance void [System.Private.CoreLib]System.Object::.ctor() | |
IL_0006: nop | |
IL_0007: ret | |
} // end of method Program::.ctor | |
} // end of class Program | |
.class private auto ansi sealed '<PrivateImplementationDetails>' | |
extends [System.Private.CoreLib]System.Object | |
{ | |
.custom instance void [System.Private.CoreLib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( | |
01 00 00 00 | |
) | |
// Nested Types | |
.class nested private explicit ansi sealed '__StaticArrayInitTypeSize=16' | |
extends [System.Private.CoreLib]System.ValueType | |
{ | |
.pack 1 | |
.size 16 | |
} // end of class __StaticArrayInitTypeSize=16 | |
// Fields | |
.field assembly static initonly valuetype '<PrivateImplementationDetails>'/'__StaticArrayInitTypeSize=16' '1456763F890A84558F99AFA687C36B9037697848' at I_00002908 | |
} // end of class <PrivateImplementationDetails> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": 1, | |
"target": "IL", | |
"mode": "Debug" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://sharplab.io/#gist:00f7dbad4c1c407e005238c85eeb65de