*----------------------------------------------------------- * BITCOUNT - count the 1 bits in a 32 bit number *----------------------------------------------------------- DATA EQU $9000 RESULT EQU $9004 BITCOUNT ORG $8000 MOVE.L DATA,D0 ;D0 holds data CLR.B D1 ;D1 counts bits MOVE.W #32,D2 ;D2 counts 32 bit loop LOOP LSR.L #1,D0 ;shift low bit into C BCC NEXT ;don't count if bit is 0 ADD.B #1,D1 ;bit is 1, count it NEXT SUB.W #1,D2 ;next bit BNE LOOP MOVE.B D1,RESULT ;store result TRAP #14 ;Return to MON68K END BITCOUNT