简体   繁体   中英

Passing array to external assembly function

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM