Created
May 7, 2013 03:55
-
-
Save v2m/5530153 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
let rec findPivot (myArray : int[]) i = | |
if i = 0 then | |
-1 | |
else | |
System.Diagnostics.Trace.Assert false | |
if myArray.[i] > myArray.[i-1] then i - 1 | |
else findPivot myArray (i - 1) | |
findPivot [| 1; 2; 3; 4 |] 3 |
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
if i = 0 then | |
00000000 push rbx | |
00000001 push rdi | |
00000002 sub rsp,28h | |
00000006 mov ebx,edx | |
00000008 mov rdi,rcx // prologue | |
0000000b nop dword ptr [rax+rax] | |
00000010 test ebx,ebx // ebx contains i | |
00000012 jne 0000000000000020 // check | |
-1 | |
00000014 mov eax,0FFFFFFFFh // -1 to eax and jmp to epilogue | |
00000019 jmp 0000000000000056 | |
0000001b nop dword ptr [rax+rax] | |
00000020 mov rcx,1F013250h | |
0000002a mov rcx,qword ptr [rcx] | |
0000002d call 000000004908C4F8 // System.Diagnostics.Trace.Assert false | |
if myArray.[i] > myArray.[i-1] then i - 1 | |
00000032 movsxd rax,ebx | |
00000035 mov rcx,qword ptr [rdi+8] | |
00000039 cmp rax,rcx | |
0000003c jae 0000000000000061 // range check | |
0000003e mov edx,dword ptr [rdi+rax*4+10h] // myArray[i] | |
00000042 dec ebx | |
00000044 movsxd rax,ebx | |
00000047 cmp rax,rcx | |
0000004a jae 0000000000000061 // range check | |
0000004c mov eax,dword ptr [rdi+rax*4+10h] // myArray[i - 1] | |
00000050 cmp edx,eax | |
00000052 jle 0000000000000058 | |
00000054 mov eax,ebx // ebx (i - 1) to eax and jmp to the epilogue | |
00000056 jmp 000000000000005A | |
else findPivot myArray (i - 1) | |
00000058 jmp 0000000000000010 // jmp to the beginning of the loop | |
0000005a add rsp,28h | |
0000005e pop rdi | |
0000005f pop rbx | |
00000060 ret | |
if myArray.[i] > myArray.[i-1] then i - 1 | |
00000061 call 000000005FA6A6D4 | |
00000066 nop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment