Hey everyone. I am just learning assembly and I am understanding everything, but I keep having a problem a with this program. The main is in C and is supposed to receive a string from a user. Then, in assembly, I am supposed to count the number of words. But whenever I run the program, it crashes. Obviously there's something wrong. Here is my program:
#include <stdio.h>
#include <stdlib.h>
extern int countwords(char string);
int main(int argc, char *argv[])
{
char mystring[256];
int count;
printf("Give me a string: ");
scanf("%s", mystring);
count = countwords(mystring);
printf("Your string has %d letters \n", count);
system("PAUSE");
return 0;
}
.global _countwords
_countwords:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %ebx
xor %esi, %esi
xor %eax, %eax
movl 0x20, %ecx
cmpb $0, (%ebx, %esi, 1)
je done
loop:
cmp %ecx, (%ebx, %esi, 1)
je word
cmpb $0, (%ebx, %esi, 1)
je done
inc %esi
jmp loop
word:
inc %eax
inc %esi
cmpb $0, (%ebx, %esi, 1)
je done
jmp loop
done:
movl %ebp, %esp
popl %ebp
ret
I was wondering if any of you more experienced programmers can help an amateur out? Any assistance would be greatly appreciated! Thanks