Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. // YOUR CODE STARTS HERE
  2. push ebp
  3. mov ebp, esp
  4. // local variable
  5. sub esp, 4
  6. push ebx // int array
  7. push ecx //to find
  8. push esi // start
  9. push eax // mid
  10. push edi // end
  11. push edx
  12. mov ebx, [ebp + 8] //array
  13. mov ecx, [ebp + 12] //find
  14. mov esi, [ebp + 16] //start
  15. mov edi, [ebp + 20] //end
  16. //mid = eax , local variable?
  17. mov eax, edi //end
  18. sub eax, esi //end-start
  19. shr eax, 1 //(end-start)/2
  20. add eax, esi //start + (end-start)/2
  21. startGend:
  22. cmp esi,edi // start to finish
  23. jg return1 // if start is bigger than finish
  24. //is it found
  25. found:
  26. cmp dword ptr[ebx + 4 * eax], ecx //compare array[mid] to to_find
  27. je done1 //return mid if they match
  28.  
  29. cmp dword ptr[ebx + 4 * eax], ecx
  30. jg recursion1 // it is greater
  31. less1: //else it is lower
  32. jmp recursion2
  33. recursion1://return binary_search(data, toFind, start, mid-1);
  34. dec eax
  35. push ebx //last parameter first array
  36. push ecx //to find
  37. push esi //start
  38. push eax // mid -1
  39. call binarySearch
  40. // add esp,16
  41.  
  42. recursion2://return binary_search(data, toFind, mid+1,end );
  43. inc eax;
  44. push ebx //array
  45. push ecx //to find
  46. push eax //mid +1
  47. push edi //end
  48. call binarySearch
  49. // add esp, 16
  50. return1:
  51. mov eax, -1
  52. jmp done1
  53. done1:
  54. pop edx
  55. pop edi
  56. pop eax
  57. pop esi
  58. pop ecx
  59. pop ebx
  60.  
  61. mov esp,ebp //local varaible stuff
  62. pop ebp
  63. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement