【发布时间】:2012-05-02 08:07:55
【问题描述】:
我遇到了一个涉及 C 和 Assembly 合作的问题。我想写一个程序,将表指针发送到汇编函数,在这个函数中,表中填充了一些数据,next返回到C并将结果写入输出。
以下代码与C部分有关:
#include <stdio.h>
extern int oblicz(double,double, double, double, int, double *);//a signature of an exter assembly function
int oblicz(double,double, double, double, int, double *);// the last position is a pointer of my table
//(some code)
size =(int)k;
tab = (double *)malloc(sizeof(double)*(size+1)); // alocation of memory
if (oblicz(a,b,P,Q,size,tab)) //the function
{
for(i;i<size;i++)
printf ("a result on %d index is %.10g \n",i, tab[i] );
}
组装部分:
%define a qword [ebp+8]
%define b qword [ebp+16]
%define P qword [ebp+24]
%define Q qword [ebp+32]
%define sizet dword [ebp+40]
%define tab dword [ebp+44]// the table pointer
为了简化代码,我使用了下面的语法,其中我只设置了 tab[0]
;i omited setting frame etc.
xor ebx,ebx
mov ebx, tab
mov qword [ebx], 4
C 的结果是
a result on: 0 -is 1.669124542e-307 // it is always the same independently of value in this line : "mov qword [ebx], 4"
如果有任何可能有问题的建议,我将不胜感激
【问题讨论】:
-
为什么不在调试器中单步调试代码?这会很快地告诉你问题出在哪里。
-
由于它始终是相同的值,因此您没有写入正确的内存位置,并且您提供的信息不足,例如arch、汇编程序、函数调用标准……设置堆栈帧的代码也会有所帮助。并 +1 以“使用调试器逐步完成”。
标签: c arrays pointers assembly