CS301 – Fall 2003
Prof. Hartman
Homework #4
Due Wednesday, October 22nd
by
a) mov
ecx,1
L5:
…
loop L5
b) L5: mov
ecx,10
…
loop L5
c) mov
ecx,0
L5:
…
loop L5
d) mov
ecx,10
L5:
inc ecx
loop L5
a) Is eax equal to or smaller than ebx?
b) Is ecx equal to or smaller than edx?
c) Is eax greater than ebx?
d) Is ecx greater than edx?
e) Does edx contain 0?
f) Did an overflow occur?
a) mov al,
0FFh
add al, 1
b) mov bl,
24h
sub bl,bl
c) mov cl,
10101010b
add cl, 01010101b
d) mov dl,
11001100b
add dl, 01110011b
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.