flat assembler
Message board for the users of flat assembler.
Index
> Windows > Wrong printf of float number. |
Author |
|
Roman 08 May 2020, 15:26
double [a]
|
|||
08 May 2020, 15:26 |
|
felement 08 May 2020, 15:40
Quote:
Where I have to put it? Sorry, but i'm newbie... |
|||
08 May 2020, 15:40 |
|
Roman 08 May 2020, 15:53
cinvoke printf, '%.2f',double [a]
|
|||
08 May 2020, 15:53 |
|
felement 08 May 2020, 16:35
thanks a lot, it works for me
|
|||
08 May 2020, 16:35 |
|
felement 08 May 2020, 16:42
anyway, i have second problem... :/
here is the code, integral calculator for given -1.25 and 2 n =100 the return should be ca = 3.5293 the result is: -1.#IND Why this is shown? Code: format PE Console entry start include 'INCLUDE/win32ax.inc' include 'INCLUDE/win_macros.inc' section '.text' code readable executable start: finit cinvoke printf, 'Begin number: ' cinvoke printf, 'a= ' cinvoke scanf, '%lf',a cinvoke printf, 'End number: ' cinvoke printf, 'b= ' cinvoke scanf, '%lf',b cinvoke printf, 'Grids(more higher accuracy): ' cinvoke printf, 'n= ' cinvoke scanf, '%d',n fld [b]; fld [a] fsubp ;(b-a) fild [n] fdivp ;(b-a)/n fst [h] ;store h = (b - a) / n; ;y(a)=2x^3 fld [a] fld [a] fmulp ;a^2 fld [a] fmulp ;a^3 fild [two] fmulp ;2(a^3) fild [one] fsubp ;2(a^3)-1 fst [ya] ;=ya ; y(b) = 2x^3 fld [b] fld [b] fmulp fld [b] fmulp fild [two] fmulp fild [one] fsubp fst [yb] ; s= y(a) + y(b) fld[ya] fld[yb] faddp fstp [s] jumper: ;int i = 1; i < n; i++ fild [i] fld [h] fmulp fld [a] faddp ;(a+i*h) fst [pom] fld [pom] fld [pom] fmulp ;(res)^2 fld [pom] fmulp ;(res)^3 fild [two] fmulp ;2(res)^3 fild [one] fsubp ;2(res)^3-1 ;y(a+i*h) fild [two] fmulp ;2*y(a+i*h) fst [teset] fld [s] faddp ;s += 2 * y( a + i * h); fst [s] ;store s; inc [i] mov edx,[i] cmp edx,[n] jb jumper;robimy taka petle do{} while(i<b); fld [h] fild [two] fdivp fld [s] fmulp fst [wynik] ; wynik = (h / 2) * s cinvoke printf, '%.4f',double [wynik],double [wynik+4] cinvoke system, 'pause' section '.data' code readable writeable executable a dq 0.0 b dq 0.0 ya dq 0.0 yb dq 0.0 h dq 0.0 s dq 0.0 pom dq 0.0 wynik dq 0.0 one dd 1 two dd 2 n dd 0 i dd 1 teset dq 0.0 |
|||
08 May 2020, 16:42 |
|
felement 08 May 2020, 17:28
i have second problem... :/
here is the code, integral calculator for given -1.25 and 2 n =100 the return should be ca = 3.5293 the result is: -1.#IND Why this is shown? Code: format PE Console entry start include 'INCLUDE/win32ax.inc' include 'INCLUDE/win_macros.inc' section '.text' code readable executable start: finit cinvoke printf, 'Begin number: ' cinvoke printf, 'a= ' cinvoke scanf, '%lf',a cinvoke printf, 'End number: ' cinvoke printf, 'b= ' cinvoke scanf, '%lf',b cinvoke printf, 'Grids(more higher accuracy): ' cinvoke printf, 'n= ' cinvoke scanf, '%d',n fld [b]; fld [a] fsubp ;(b-a) fild [n] fdivp ;(b-a)/n fst [h] ;store h = (b - a) / n; ;y(a)=2x^3 fld [a] fld [a] fmulp ;a^2 fld [a] fmulp ;a^3 fild [two] fmulp ;2(a^3) fild [one] fsubp ;2(a^3)-1 fst [ya] ;=ya ; y(b) = 2x^3 fld [b] fmulp fmulp fild [one] fsubp fst [yb] ; s= y(a) + y(b) fld[ya] fld[yb] faddp fstp [s] fild [i] fld [h] fmulp fld [a] faddp ;(a+i*h) fst [pom] fmulp ;(res)^3 fild [two] fmulp ;2(res)^3 fild [one] fsubp ;2(res)^3-1 ;y(a+i*h) fild [two] fmulp ;2*y(a+i*h) fst [teset] fld [s] faddp ;s += 2 * y( a + i * h); fst [s] ;store s; fld [h] fild [two] fdivp fld [s] fmulp fst [wynik] ; wynik = (h / 2) * s cinvoke printf, '%.4f',double [wynik],double [wynik+4] cinvoke system, 'pause' section '.data' code readable writeable executable a dq 0.0 yb dq 0.0 h dq 0.0 s dq 0.0 pom dq 0.0 wynik dq 0.0 one dd 1 two dd 2 n dd 0 i dd 1 teset dq 0.0 Last edited by felement on 08 May 2020, 19:23; edited 2 times in total |
|||
08 May 2020, 17:28 |
|
Roman 08 May 2020, 19:01
sometime use IDA pro for debug you code.
cinvoke printf, '%.4f',double [wynik],double [wynik+4] may be cinvoke printf, '%.4f',double [wynik] |
|||
08 May 2020, 19:01 |
|
felement 08 May 2020, 19:23
fstp [s] (not fst [s] )- the number exceeded the size.
|
|||
08 May 2020, 19:23 |
|
Roman 09 May 2020, 07:56
fld [b];
fld [a] fsubp ;(b-a) Use sse. 8 xmm registers. movsd xmm1,[b] ;for double float subsd xmm1,[a] for float: movss xmm1,[b] subss xmm1,[a] convert int to float: cvtsi2ss xmm1,eax convert float to int: cvtss2si eax,xmm1 convert double(xmm1) to float(xmm2): cvtsd2ss xmm2,xmm1 |
|||
09 May 2020, 07:56 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.