开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜