CS301 – Fall 2001
Prof. Hartman
Homework #4
Due Monday, October 8th
by 5:00 pm
int
bit_count(unsigned int x )
{
int
cnt = 0;
while(
x != 0) {
x = x & (x-1);
cnt++;
}
return
cnt;
}
Write your code using subroutines,
and use no static variables – that is, your .data and .bss segments should be
empty except for string data. (If you need local variables, use stack space as
in local1.asm or local2.asm) Pass
any parameters to your routines on the stack, and return the answer in EAX.
Your program should ask the user to enter an integer, and report the answer
that each subroutine returns.
You may use the I/O routines from Carter’s book. Refer to the handout about using NASM with Windows and Visual C++ for links to the I/O files if you don’t have them. For full credit you must turn in a well-commented listing including your name and the problem number.