Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site watdaisy.UUCP Path: utzoo!watmath!watdaisy!ndiamond From: ndiamond@watdaisy.UUCP (Norman Diamond) Newsgroups: net.puzzle Subject: Re: 68000 Code Puzzle (spoiler) Message-ID: <7083@watdaisy.UUCP> Date: Mon, 18-Mar-85 14:18:59 EST Article-I.D.: watdaisy.7083 Posted: Mon Mar 18 14:18:59 1985 Date-Received: Tue, 19-Mar-85 03:45:11 EST References: <1059@decwrl.UUCP> <2830@dartvax.UUCP> Organization: U of Waterloo, Ontario Lines: 36 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."