Reputation: 65
I've got a problem which concern C and Assembly cooperation. I would like to write a program which sending a table pointer to assembler's function, and in this function the table is filled of some data, next is returned to C and results are written to output.
The following code relate to C part:
#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] );
}
Assembly part:
%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
to make a code accomplishment simple I used below syntaxt in which Im setting only tab[0]
;i omited setting frame etc.
xor ebx,ebx
mov ebx, tab
mov qword [ebx], 4
and result in C is
a result on: 0 -is 1.669124542e-307 // it is always the same independently of value in this line : "mov qword [ebx], 4"
I would be gratful for any suggestion what may be wrong
Upvotes: 0
Views: 604
Reputation: 65
Thank you I finally understood what was my mistake. I found also solution based on your idea. and this is the answer on question how to repair it:
First simple declaration:
segment .data
Four dw 4
next
mov ebx, tab
fild word [Four] //conversion int->
mov ebx, tab
fstp qword [ebx] // pop from stack streight to tab
Maybe it's a little crappy but it works. Thanks also for avices of using gdb ;). It's really usefull.!
Upvotes: 0
Reputation: 86661
So you are moving the literal integer 4 to the first element of tab. The first element will look like this:
04 00 00 00 00 00 00 00
^^ low address ^^ high address
In IEEE 754 double precision numbers, the exponent is in the top bits and in your case is zero. As the fraction is non zero (4 in your case), you have a subnormal number. This means that you have written a very small number and not 4.
I'm guessing you want to move the double version of 4 to that address.
Upvotes: 1