6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Tue May 07, 2024 12:06 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Binary Search for 65C816
PostPosted: Fri Jun 27, 2014 7:21 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8176
Location: Midwestern USA
In the process of getting from one place to another, I needed to concoct a binary search algorithm for the 65C816 running in native mode. The job was to look up display control "mnemonics" (actually parameterless macros) embedded in text strings and then send an escape sequence to the display device to produce the desired result. I chose the binary search because quite a few of these mnemonics could be used, making rapid performance essential.

Anyhow, I subsequently generalized my code so that it can be used to search through an ordered list of character strings of varying lengths, e.g, a list of names, using a 16 bit pointer array to index the strings. All working storage is on the stack. Code is attached, and has been submitted to Mike for inclusion in the code library. There's plenty of commentary so you can see what's going on.
Attachment:
File comment: Binary Search for 65C816
bsrch816.zip [199.42 KiB]
Downloaded 96 times

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 02, 2014 12:31 pm 
Offline

Joined: Fri Sep 28, 2012 12:27 pm
Posts: 25
Location: Boulogne Billancourt, France
I do not know if the mentionned algorithm could be applied in this context but there is a 6502 Assembly sample code at the URL http://www.txbobsc.com/aal/1985/aal8506.html that describes how a "Boyers Moore Morris" search algorithm could be implemented (looking up occurences of a single string pattern in a large text body). I understand that what you are looking for is to extract multiple patterns as soon as possible from a character stream.

HTHATS,
Benoît


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 02, 2014 3:33 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8176
Location: Midwestern USA
Benoit0123 wrote:
I do not know if the mentionned algorithm could be applied in this context but there is a 6502 Assembly sample code at the URL http://www.txbobsc.com/aal/1985/aal8506.html that describes how a "Boyers Moore Morris" search algorithm could be implemented (looking up occurences of a single string pattern in a large text body). I understand that what you are looking for is to extract multiple patterns as soon as possible from a character stream.

HTHATS,
Benoît

Firstly, it's the "Boyer-Moore" algorithm.

Fundamentally different problems are being solved.  Boyer-Moore addresses the case of searching through an arbitrary range of memory looking for a specific pattern.  A binary search works through an ordered list looking for the pattern.  Hence only log2N comparisons are required to determine whether or not the search pattern is present.  With Boyer-Moore, performance rapidly degrades as more of the range being searched consists of alike characters, e.g., long strings of $00, peppered with an occasional $01 in a case where $01 $01 is being sought.  In such a case, Boyer-Moore becomes more like the brute force method in performance, but actually worse, because of the overhead needed to maintain the incidence table.

An aspect of Boyer-Moore that could be considered a negative in some cases is the need for the incidence table to be equal in size to all possible byte values.  In some 6502 systems, having to devote a full page of RAM in support of a search may be a lot to ask.  I gave that some thought when I wrote the search (H) function in Supermon 816.  During testing, I concluded that the performance of the brute force method was more than acceptable, so I did not use Boyer-Moore.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: