Counting the number of set bits in an integer

function CountBits(const Value: Integer): Integer;
asm
  mov  ecx, eax
  xor  eax, eax
  test ecx, ecx
  jz   @@ending
 @@counting:
  shr  ecx, 1
  adc  eax, 0
  test ecx, ecx
  jnz  @@counting
 @@ending:
end;

Source: www.guidogybels.net.