I keep getting error messages when I search for the numbers that are within the range of the top 1/4 of my array. For example, any numbers above 76 are not searchable. Plus, any numbers that are lower than my lowest number in the array or higher than my highest number are impossible, too. Any suggestions?
I've tried switching among memories so many times, but still no use.
program BinarySearch;
#include("stdlib.hhf")
const ArraySize := 17;
static
SortedData: uns32 [ArraySize] := [ 15, 20, 25, 30, 35, 40, 45, 50,
55, 60, 65, 70, 75, 80, 85, 90, 95 ];
found: boolean := false;
searchItem: uns32;
begin BinarySearch;
stdout.put(nl, "Enter a two-digit number for search: ");
stdin.get(searchItem);
mov(0, ecx);
mov(ArraySize - 1, eax);
while(ecx <= eax && found == false) do
add(ecx, eax);
mov(eax, ebx);
mov(0, edx);
div(2, edx:eax);
mov(eax, edx);
mov(ebx, eax);
mov(edx, ebx);
mov(searchItem, edx);
if(edx < SortedData[ebx * 4]) then
sub(1, ebx);
mov(ebx, eax);
elseif(edx > SortedData[ebx * 4]) then
add(1, ebx);
mov(ebx, ecx);
else
mov(true, found);
endif;
endwhile;
stdout.put(nl, "Binary Search : ", nl);
for(mov(0, ecx); ecx < ArraySize; inc(ecx)) do
stdout.puti32Size(SortedData[ecx * 4], 4, ' ');
endfor;
stdout.newln();
if(found) then
stdout.put("Found, Search item: ", searchItem, nl);
else
stdout.put("Not Found, Search item: ", searchItem, nl);
endif;
end BinarySearch;