ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1001. Reverse Root

inline assembly
Posted by zfoolj 8 Aug 2009 08:00
Can anybody tell me where is wrong ?
I have tested it with random real numbers and it worked fine.
I don't know much about FPU.

#include "stdio.h"

char sIn[]  = "%lf";
char sOut[] = "%.4lf\n";

double d[150000];

int main(){
        __asm{
                push    ebx
                mov     ebx,    0h
                sub     ebx,    8h
        A1:
                add     ebx,    8h
                lea     eax,    d[ebx]
                push    eax
                mov     eax,    offset sIn
                push    eax
                call    dword ptr scanf
                add     esp,    8h
                cmp     eax,    EOF
                jne     A1

                fwait
                finit
        A2:
                sub     ebx,    8h
                cmp     ebx,    0h
                jl      A3
                sub     esp,    8h
                lea     eax,    d[ebx]
                fld     qword ptr [eax]
                fsqrt
                fstp    qword ptr [esp]
                mov     eax,    offset sOut
                push    eax
                call    dword ptr printf
                add     esp,    0ch
                jmp     A2
        A3:
                pop     ebx
        }
        return 0;
}