Question

Somehow related to this calling assembly functions from c

I'm passing to that function an array of int and a length:

do_stuff_in_asm (array, len);

The assembly part looks like this

...................
movl 8(%ebp), %eax
movl 12(%ebp), %ecx
movl $0, %edi
...................
movl (%eax,%edi,4), %edx
pushl %edx
pushl $printtext
call printf
addl $8, $esp
..................

I can print the len argument 12(%ebp), but every time I try the same thing on %edx which should be the first element of the array I get a segmentation fault.

int *array, n, i;

printf ("Give array size: ");
scanf("%d",&n);

array = malloc (n * sizeof(int));

Then it's filled up with data.

Was it helpful?

Solution

You should have posted complete code. As an illustration, I have written this sample program. Note, it is only inline asm so that ideone can compile it from a single file. As you can see the code you posted, when used properly, does work. So the problem must be in some other part that you have omitted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top