I'm rather new to assembly programming. I'm using the x86 platform with GCC (Linux).
I have a function that I want to call from C as:
myfunc ( unsigned char * s1, unsigned char * s2, int someint );
The function will take the s1 and s2 memory locations and compare them, then increment and compare, etc., doing some processing as it goes. This is sort of like memcmp but I'm doing more.
My question: if I pass a pointer into an assembly function? And then how do I say "give me the value stored at this memory address"?
Here's what I have so far:
To get the first function arg ("s1") off the stack, I do this (someaddress is a 32-bit integer, and I'm working on a 32-bit processor):
movl 8(%esp), %ecx
movl %ecx, someaddress
If I put somevar into %eax (or %ebx, etc.) and then printf it with %p, I see that its address and the address of the unsigned char pointer "s1" I passed it are the same. But I suspect that what I've actually done is taken the memory address, converted it to an integer, and then put that integer in someaddress.
For example, if I then do this:
movl pos1, %eax
movl pos2, %ebx
cmp (%eax),(%ebx)
I get "Error: too many memory references for `cmp'". I'm not entirely certain what that means, except "you screwed up" ;-)
So...
- how to pass a pointer in and keep it as a pointer?
- how to use the value of said pointer in assembly? (e.g., like
*ptrin C)
Do I want to look at the LEA operand?
I'm using Richard Blum's "Professional Assembly Programming" as my guide, but Blum doesn't seem to cover this case.
Update
Thank you very much for your learned response!
Unfortunately, I'm still not able to dereference.
Here is a simplified example.