I am tring to compare a character from a char pointer, i.e. a string, with another specified char, to find the first occurence of that char in the string. However, the char from the char pointer is returning wierd values, I am not sure how to do it.
This is my assembly code:
findChar:
mov $0, %eax
start:
cmp (%rdi), %esi
je done
add $1, %rdi
inc %ebx
jmp start
done:
ret
I am calling the this function from C:
int findChar( char *str, char ch );
I tried returning the value of (%rdi) when it was supposed to match. When printing the return value as a char it is correct, however the integer value is something like 112410010, i.e. alot.
Thanks for any help
%esias that may be properly zero extended to 32-bits, the problem is that the memory access via(%rdi)is also 32-bits because of the size of%esi, so it is grabbing 4 characters at once from memory. Usecmp (%rsi), %silinstead for an 8-bit memory access and 8-bit compare.%silinstead of$0since you're implementingrawmemchrinstead ofstrlen.