assembly - Compiling ASM with C and having result "NaN" or "-NaN". Square Root Function -


i had errors compiling earlier after working on them, got no errors/warnings. altho result given nan.

here code:

c:

iclude <stdio.h>  extern float wynik1 (int a, int b, int c); extern float wynik2 (int a, int b, int c);  int = 2; int b = 2; int c = 2;  int main () {  float licz1 = 0; float licz2 = 0;  licz1 = wynik1(a, b, c); licz2 = wynik2(a, b, c);  printf("roots : %f oraz %f \n", licz1, licz2);  return 0; } 

asm1:

sysexit = 1 sysread = 3 syswrite = 4 stdout = 1 exit_success = 0 stdin = 0  .align 32 .data  a: .int 2 b: .int 2 c: .int 2 buf: .float 0 x1: .float 0  cztery: .float 4 dwa: .float 2  .text .global wynik1  wynik1:  xor %eax, %eax xor %ebx, %ebx xor %ecx, %ecx  pushl %ebp movl %esp, %ebp movl 8(%ebp), %ecx movl 12(%ebp), %ebx movl 16(%ebp), %eax pushl %eax pushl %ebx pushl %ecx  movl %eax, movl %ebx, b movl %ecx, c  finit  fld fld c  deltaa1: fmulp fld cztery fmulp fld b fld b fmulp fsubp  pierwiastek1: fsqrt fld b fchs fsubp fstp buf fld fld dwa fmulp fld buf fdivp fstp x1  movl x1, %eax  movl %ebp, %esp popl %ebp ret 

asm2:

sysexit = 1 sysread = 3 syswrite = 4 stdout = 1 exit_success = 0 stdin = 0  .align 32 .data  a: .int 2 b: .int 2 c: .int 2 buf: .float 0 x2: .float 0 cztery: .float 4 dwa: .float 2  .text .global wynik2  wynik2:  xor %eax, %eax xor %ebx, %ebx xor %ecx, %ecx  pushl %ebp movl %esp, %ebp movl 8(%ebp), %ecx movl 12(%ebp), %ebx movl 16(%ebp), %eax pushl %eax pushl %ebx pushl %ecx  movl %eax, movl %ebx, b movl %ecx, c  finit  fld fld c  deltaa2: fmulp fld cztery fmulp fld b fld b fmulp fsubp  pierwiastek2: fsqrt fld b fchs faddp fstp buf fld fld dwa fmulp fld buf fdivp fstp x2   movl %ebp, %esp popl %ebp ret 

so yeah. return in c code "- nan , - -nan". have no idea hod overcome after hours of checking registers , changing code.

code in c = intput , output.

asm1 couting root 1 , asm2 counting root 2.

any ideas?

you doing fld a, while should doing fild a load integer floating point stack (converting float); variables integers, not floats.

e.g. integer 2 loaded float denormal magnitude of 2^-140. multiplied small number makes zero.

then last fdivp divides 0.0 0.0, definition nan.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -