Reputation: 2293
I'm new to asm and using string in.
1/I've got a string and I want to return the adress of the first caracter. (I call the asm function in the C main).
I've tried :
movl $str, %eax
According to me, it returns the string.
With movl $(str), %eax
it returns the adress of the first caracter of the string ?
If I want to return the adress of the second character in the string, I don't understand how I can do that in asm.
I diplay result in the C program like that :
printf("string : %s, adress : %d\n", function_asm(), function_asm()).
It returns me "string : programmation, adress : 134520852" I think that "134520852" is not an adress and there is something I don't understand.
2/I've seen there are %edi
, %esi
and functions for string but I can't find a good (easy) tutorial using that. I've just understand that %edi is for index source and %esi for index destination...do you know some links about it ?
thanks in advance ! :-)
Upvotes: 0
Views: 2183
Reputation: 881383
If you know how to get the address of the first character of a string into eax
, the address of the second charcter can be obtained with a simple inc %eax
(increment eax register).
I'm not sure why you think 134520852
is not the address of your string, especially if that string is indeed "programmation"
- that would be prrof that the return from function_asm()
was okay. Perhaps you would be happier printing it as a pointer, with %p
.
And you're basically correct about %edi
and %esi
though you have them the wrong way around. %esi
is the source one and %edi
is the destination one.
Upvotes: 2