Here is what I need to do.
I have a very small C program that takes user input and passes argv to a function written in GNU assembly language that will then count the number of characters in the string.
The function seems to work fine when I enter a string as a variable directly in the program, but when I try to pass it from C, it gives me an incorrect count.
Here is my C code:
#include <stdio.h>
#include <stdlib.h>
extern int my_strlen(char*);
main(int argc, char *argv[])
{
printf("\nThe number of characters is %i\n\n.", my_strlen(argv[1]));
return 0;
}
Here is my assembly code. Please note that I need to keep this as a loop.
.globl my_strlen
.type my_strlen, @function
my_strlen:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %ebx
movl $0, %eax
loop:
incl %ebx
cmpl $0, (%ebx)
je end_loop
incl %eax
jmp loop
end_loop:
cmpl $0, %eax
je empty
jmp not_empty
not_empty:
decl %eax
empty:
movl %ebp, %esp
popl %ebp
ret
If I run the application "./test test", it gives me a character count of 1188. It should be 4...
Thanks.