0

I want to code this recursive binary search in assembler motrolla 68K.

int binSearch(int key, int &lo, int &hi) {
if(hi < lo)
   return NOT_FOUND;  //RETURN with V = 1  
int mid = (lo+hi) / 2;
if(key == array[mid])
   return mid;
else if(key < array[mid]) // go left
   return binSearch(key, lo, mid-1); // left
else
   return binSearch(key, mid+1, hi); // right
}

so I am just wondering if I am coding the int binsearch(int key,int&lo,int &hi) part right

any helP!!????????????

link       A6,#0
movem.l    D1,D2-(sp)
move.w     8(A6),D1 *key

and if I wanted to do int&low,int hi would I do the same thing just with A5,A4..ect.?

4

1 回答 1

0

I found these points you might consider reviewing in your code:

  • You need to pass array to binsearch
  • This will only work if array is previously sorted
  • The type of array contents should be int, to make a valid comparison with key

ps: please, could you clarify on the second part? Are you trying to convert C to Assembly?

于 2013-06-11T23:52:30.443 回答