home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 21866 < prev    next >
Encoding:
Internet Message Format  |  1993-01-21  |  1.3 KB

  1. From: bayes@hplvec.LVLD.HP.COM (Scott Bayes)
  2. Date: Tue, 19 Jan 1993 17:51:51 GMT
  3. Subject: Re: (Q) Need bit manipulation algorithm
  4. Message-ID: <830026@hplvec.LVLD.HP.COM>
  5. Organization: Hewlett-Packard Co., Loveland, CO
  6. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!hpscit.sc.hp.com!hplextra!hpfcso!hplvec!bayes
  7. Newsgroups: comp.sys.mac.programmer
  8. References: <1993Jan6.022430.19469@leland.Stanford.EDU>
  9. Lines: 23
  10.  
  11. > name, but whose initials are M.A.C.  And if you want a solution for
  12. > a word, and you don't want a 32K lookup table, you actually have to
  13. > _shift_!  Shifting is for weenies.
  14.  
  15. But for a word, it's just the sum of the bits in each byte. Code something
  16. like this (untested) should do it PDQ.
  17.  
  18. ---
  19.  
  20. * at beginning, d0 contains a word whose "1" bits we wish to count
  21. * at end, d2 contains number of 1 bits in its lower byte
  22.  
  23.         moveq   #0,d1                   - clear table index register
  24.         move.b  d0,d1                   - lower byte of data word
  25.         move.b  btable(d1.w),d2         - nbits for lower byte (PC relative)
  26.         lsr.w   #8,d0                   - access upper byte of data word
  27.         move.b  d0,d1                   - upper byte of data word
  28.         add.b   btable(d1.w),d2         - d2 contains total bits of word
  29.  
  30. ---
  31.  
  32. ScottB
  33.