Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // YOUR CODE STARTS HERE
- push ebp
- mov ebp, esp
- // local variable
- sub esp, 4
- push ebx // int array
- push ecx //to find
- push esi // start
- push eax // mid
- push edi // end
- push edx
- mov ebx, [ebp + 8] //array
- mov ecx, [ebp + 12] //find
- mov esi, [ebp + 16] //start
- mov edi, [ebp + 20] //end
- //mid = eax , local variable?
- mov eax, edi //end
- sub eax, esi //end-start
- shr eax, 1 //(end-start)/2
- add eax, esi //start + (end-start)/2
- startGend:
- cmp esi,edi // start to finish
- jg return1 // if start is bigger than finish
- //is it found
- found:
- cmp dword ptr[ebx + 4 * eax], ecx //compare array[mid] to to_find
- je done1 //return mid if they match
- cmp dword ptr[ebx + 4 * eax], ecx
- jg recursion1 // it is greater
- less1: //else it is lower
- jmp recursion2
- recursion1://return binary_search(data, toFind, start, mid-1);
- dec eax
- push ebx //last parameter first array
- push ecx //to find
- push esi //start
- push eax // mid -1
- call binarySearch
- // add esp,16
- recursion2://return binary_search(data, toFind, mid+1,end );
- inc eax;
- push ebx //array
- push ecx //to find
- push eax //mid +1
- push edi //end
- call binarySearch
- // add esp, 16
- return1:
- mov eax, -1
- jmp done1
- done1:
- pop edx
- pop edi
- pop eax
- pop esi
- pop ecx
- pop ebx
- mov esp,ebp //local varaible stuff
- pop ebp
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement