ndiamond@watdaisy.UUCP (Norman Diamond) (03/18/85)
Chuck Simmons writes: > My puzzle is written in 68000 code, and it does not do anything nearly > as common as perform a binary search. (This puzzle is due to Mike Morton, > the author of the reaganagrams published in a recent Scientific American.) > d0, d1, and d2 are 32 bit registers. > > move.w #32,d2 ; d2 = 32 > bra.s start ; jump into our loop > lp: or.l d1,d0 ; d0 |= d1 > start: move.l d0,d1 ; d1 = d0 > add.l #1,d0 ; d0 = d0 + 1 > dbcs d2,lp ; if carry is clear, then decrement d2, > ; and if d2 != 0 goto lp. > ; (Thus if the carry is set or if d2 becomes 0, > ; we will leave the loop.) When the Z80 code puzzle was posted, I mailed to the author instead of posting a spoiler. It's nice to see that I figured it out correctly. If spoilers are really the way to go, here is mine: The above code counts the 1-bits in the original contents of d0, and leaves the count in d2. I'm sorry I don't have another puzzle to suggest (except maybe some code turned in by third-year students :-) :-( ). -- Norman Diamond UUCP: {decvax|utzoo|ihnp4|allegra}!watmath!watdaisy!ndiamond CSNET: ndiamond%watdaisy@waterloo.csnet ARPA: ndiamond%watdaisy%waterloo.csnet@csnet-relay.arpa "Opinions are those of the keyboard, and do not reflect on me or higher-ups."