Skip to content

Instantly share code, notes, and snippets.

@v2m
Created May 7, 2013 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v2m/5530153 to your computer and use it in GitHub Desktop.
Save v2m/5530153 to your computer and use it in GitHub Desktop.
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
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