Population count

You are encouraged to solve this task according to the task description, using any language you may know.
The   population count   is the number of   1s   (ones)   in the binary representation of a non-negative integer.

Population count   is also known as:

   pop count
   popcount 
   sideways sum
   bit summation 
   Hamming weight 


For example,   5   (which is   101   in binary)   has a population count of   2.


Evil numbers   are non-negative integers that have an   even   population count.

Odious numbers     are  positive integers that have an    odd   population count.



Task

 write a function (or routine) to return the population count of a non-negative integer.
 all computation of the lists below should start with   0   (zero indexed).
 display the   pop count   of the   1st   thirty powers of   3       (30,   31,   32,   33,   34,   ∙∙∙   329).
 display the   1st   thirty     evil     numbers.
 display the   1st   thirty   odious   numbers.
 display each list of integers on one line   (which may or may not include a title),   each set of integers being shown should be properly identified.


See also
 The On-Line Encyclopedia of Integer Sequences:   A000120 population count.
 The On-Line Encyclopedia of Integer Sequences:   A000069 odious numbers.
 The On-Line Encyclopedia of Integer Sequences:   A001969 evil numbers.


	cpu	8086
	bits	16
	org	100h
section	.text
	;;;	Calculate hamming weights of 3^0 to 3^29.
	;;;	3^29 needs a 48-bit representation, which
	;;;	we'll put in BP:SI:DI.
	xor	bp,bp		; BP:SI:DI = 1
	xor	si,si
	xor	di,di
	inc	di
	mov	cx,30
	;;;	Calculate pop count of BP:SI:DI
pow3s:	push	bp		; Keep state
	push	si
	push	di
	xor	ax,ax		; AL = counter
ham48:	rcl	bp,1
	rcl	si,1
	rcl	di,1
	adc	al,ah
	mov	dx,bp
	or	dx,si
	or	dx,di
	jnz	ham48
	pop	di		; Restore state
	pop	si
	pop	bp
	call	outal		; Output
	;;;	Multiply by 3
	push	bp		; Keep state
	push	si
	push	di
	add	di,di 		; Mul by two (add to itself)
	adc	si,si
	adc	bp,bp
	pop	ax		; Add original (making x3)
	add	di,ax
	pop	ax
	adc	si,ax
	pop	ax
	adc	bp,ax
	loop	pow3s
	call	outnl
	;;;	Print first 30 evil numbers
	;;;	This is much easier, since they fit in a byte,
	;;;	and we only need to know whether the Hamming weight
	;;;	is odd or even, which is the same as the built-in
	;;;	parity check
	mov	cl,30
	xor	bx,bx
	dec	bx
evil:	inc	bx		; Increment number to test
	jpo	.next		; If parity is odd, number is not evil
	mov	al,bl		; Otherwise, output the number
	call	outal
	dec	cx		; One fewer left
.next:	test	cx,cx
	jnz	evil		; Next evil number
	call	outnl
	;;;	For the odious numbers it is the same
	mov	cl,30
	xor	bx,bx
	dec	bx
odious:	inc	bx
	jpe	.next 		; Except this time we skip the evil numbers
	mov	al,bl
	call	outal
	dec	cx
.next:	test	cx,cx
	jnz	odious
	;;;	Print newline
outnl:	mov	ah,2
	mov	dl,13
	int	21h
	mov	dl,10
	int	21h
	ret
	;;;	Print 2-digit number in AL
outal:	aam
	add 	ax,3030h
	xchg	dx,ax
	xchg	dl,dh
	mov	ah,2
	int	21h
	xchg	dl,dh
	int	21h
	mov 	dl,' '
	int	21h
	ret