#include<stdio.h>
int bitcount(unsigned x)
{
int i=0;
while(x&=(x-1))
{
i++;
}
}
main ()
{
int i=0;
i=bitcount(45);
printf("i=%d\n",i);
}
.file "p2-9.c"
.text
.globl bitcount
.type bitcount, @function
bitcount:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl $0, -4(%ebp)
jmp .L2
.L3:
addl $1, -4(%ebp)
.L2:
movl 8(%ebp), %eax
subl $1, %eax
andl %eax, 8(%ebp)
cmpl $0, 8(%ebp)
jne .L3
leave
ret
.size bitcount, .-bitcount
.section .rodata
.LC0:
.string "i=%d\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
movl $0, 28(%esp)
movl $45, (%esp)
call bitcount
movl %eax, 28(%esp)
movl $.LC0, %eax
movl 28(%esp), %edx
movl %edx, 4(%esp)
movl %eax, (%esp)
call printf
leave
ret
.size main, .-main
.ident "GCC: (Ubuntu 4.4.1-4ubuntu8) 4.4.1"
.section .note.GNU-stack,"",@progbits