简体   繁体   English

将数组传递给外部装配函数

[英]Passing array to external assembly function

Somehow related to this calling assembly functions from c c中的调用汇编函数有关

I'm passing to that function an array of int and a length: 我正在向该函数传递一个int和一个长度的数组:

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. 我可以打印len参数12(%ebp),但是每次我在%edx上尝试相同的操作时,它应该是数组的第一个元素,我都会遇到分段错误。

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. 注意,它仅是内联汇编,因此ideone可以从单个文件中对其进行编译。 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. 因此,问题一定出在您已省略的其他部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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