I just would like to add that the program that I posted some days ago can be
used to do non matching searches as well. In the not-found case the loop is left
with R6 containing the index (and R7 the address) of the element that matches
best (the element that has been compared in the last execution of the loop and
has found not to be equal to the search argument), and it is left to the caller
to take appropriate action after examining the found resp. not found return
code. The binary search logic itself stays the same and is no more complicated.
To make it easier to follow this, I post the code once again:
XR R9,R9 DURCHLAUFZAEHLER = 0
* MITTE DER RESTL. ELEMENTE ERMITTELN
LA R6,0(R4,R5) R5+R4->R6 (ANZ. ELEMENTE)
SRA R6,1 DURCH 2 DIVIDIEREN
AR R7,R3 TATSAECHL. ADR. MITTE
LR R5,R6 GROESSER, WEITERSUCHEN
LA R4,1(R6) KLEINER, WEITERSUCHEN
For some explanations regarding the SP macros used (and other topics) see
earlier in this thread.
Am Montag, 28. Oktober 2013 13:20 schrieben Sie:
> There is one respect in which this thread on binary search has been
> unsatisfactory. It has concerned itself only with match-seeking
> binary search, and bounds-seeking binary search is at least as
> A greatest lower bound (GLB) on a search argument or a least upper
> bound (LUB) on it came be searched for in the same tables in which
> matches are sought.