0

I use nasm and FPU x86 Instructions. now let's say i have in FPU st0 0. i have variable :

jedynka: dd 1.0

and now operation:

 fiadd   [jedynka]  

doesn't work, error in nasm:

error: opeartion size not specifed

when:

 fiadd dword [jedynka]

, the result (when st0 = 0 ) is :

10652320

and not 1 assembly code:

   ;lepiej od 0 do n-1  dlatego
;WZOR NA PI: 4 (1 - 1/3 + 1/5 - 1/7 + 1/9...)
 section .text use32
        global  _liczbae
        _liczbae:
                   push    ebp
                mov ebp, esp ; ramka stosu
        ; [ebp]    old EBP location  ; [ebp+4]  return point from procedure
        ; [ebp+8]  the first parameter of the procedure,  ; [ebp+12] the second parameter of the procedure
        finit   ; inicjalizacja FPU
                fld1  ; st ostatni -> bit_znaku
                fstp dword [bit_znaku] ; 1->dodatni, domyslnie jest jedynka

        fild dword [ebp+8] ;  ładujemy int n do st0
        fld1
        fsubp st1,st0
        ;jmp koniec
        ;fisub [minus_jedynka]
        ;jmp koniec
          fstp dword [n]  ; zapisujemy st0 pod adresem [n] i zrzucamy st0 ze stosu , mam tam n-1
        fldz ;na wynik st ostatni st0
 petla:
  fld dword [n_biezace] ; st0 n_biezace st1 wynik
  fld dword [dwojka] ;wynik w st2 teraz
  fmulp st1,st0 ; 2 * biezace 'n'

  fiadd  dword [jedynka]  ;  1 + st0
    jmp koniec
  ;jmp koniec
 ; fld1
 ;faddp ; mam juz 2'n' +1  w st0 ; 1. 2*'0'+1 = 1.

  fld1 ;wynik w st2 teraz

  fxch st1 ;zamiana st1<-->st0  st0 2n+1 ,st1 1
  fdivp st1,st0 ; 1/(2n+1) 1.  1/1 = 1.     ;wynik st1
  ;czy teraz ma być ujemny element?
  fld dword [bit_znaku]
  ftst ; porownuje z '0'
    fstsw ax    ; zapisujemy stan FPU do AX
    sahf        ; wrzucamy rejestr AH do rejestru flag

        je ujemny
        jmp dodatni
        ujemny:
        fld1
        faddp
        fstp dword [bit_znaku] ; zmieniony bit_znaku zapisuje
        fchs ;zmieniam znak st0
        jmp dalej

        dodatni:
        fld1
        fsubp
        fstp dword [bit_znaku] ; zmieniony bit_znaku zapisuje
        dalej:

  faddp st1,st0 ; zapisanie do wyniku
 ;  jmp koniec

  ;dodanie '1' od licznika [n_biezace]:  
  fild dword [n_biezace]
  fld1
  faddp st1,st0
   ;sprawdze czy 'n_biezace' = n ? jesli tak to koniec
    fld dword [n]
  fcomp st1 ; porownaj st1 z st0
  fstsw ax
sahf
  fstp dword[n_biezace] ; zapisuje nowe 'n'
 jne petla ; jesli nie rowne skocz do 'petla'

 koniec:
 ;fld dword [czworka]; razy 4 na koniec
 ;fmulp st1,st0;
 ;wynik + 1 ; bo niz uwzgledniłem n=0 np.
    leave          ; usuwa ramke stosu
    ret            ; wartosc zwracana to wartosc z rejestru st0

n_biezace:  dd 0.0
n:      dd  0.0 ;od n=20 do n=0
dwojka:  dd 2.0
bit_znaku  dd 0.0
czworka:  dd 4.0
minus_jedynka: dd -1.0
jedynka:   dd    1.0

C code:

#include <stdio.h>

extern double liczbae(int n);

int main()
{
    int n = 10;

        double wynik;
    int wait = 0;
    printf("Program liczy wartosc e z podana dokladnoscia");
        printf("\n\nPodaj dokladnosc: ");
    scanf("%d", &n);
        wynik = liczbae(n);
        printf("\ne = %1.16f", wynik);
                scanf("%d", &wait);
    return 0;
}

important lines, where i jump is 27,28:

 fiadd  dword [jedynka]  ;  1 + st0
    jmp koniec

how to fix it ?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Kamil Witkowski
  • 1,978
  • 1
  • 19
  • 33
  • add the size of the operand?? If `jedynka` is defined as a dword then `fiadd dword [jedynka]` – Gunner Jan 12 '14 at 19:39
  • hm, jedynka is 'dd' , but if i type fiadd dword [jedynka], the result (when st0 = 0 ) is : 10652320, and not '1' :O – Kamil Witkowski Jan 12 '14 at 19:42
  • Post your full code, we cannot help you with a few instructions. – Gunner Jan 12 '14 at 19:43
  • now you can see full code – Kamil Witkowski Jan 12 '14 at 19:46
  • 2
    1.0 is not an int (or rather, it kind of is, but it's not 1 as an int, apparently it's 10652320), so either: 1) use 1 (no .0) or 2) use `fadd` (not `fiadd`) – harold Jan 12 '14 at 19:47
  • The title question is a duplicate of [operation size not specified](//stackoverflow.com/q/27679024). The separate question at the bottom is from treating the FP binary32 bit-pattern for `1.0` *as an integer* and converting *that* to FP as an input to FP addition. That's what `fiadd` is for, don't use it if your data is already FP. But that's not an answer to the title question so I'm not posting it as an answer. – Peter Cordes Aug 28 '19 at 08:32

0 Answers0