News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How to get a integer arithmetic into variable?

Started by x64Core, October 19, 2012, 08:36:43 AM

Previous topic - Next topic

x64Core

hey guys what is up?  :biggrin:
I need a bit of help please, I have a txt file with these lines:


0.12
0.45
1.80
20.01

so, how can I have theses values into a variable? I have tried do it with FPU instructions but without success, well, I have no many experience with FPU instructions :P some reference? code? or website  :biggrin: thanks!

jj2007

See \masm32\help\hlhelp.chm, C Runtime Conversions

Or see MovVal together with Recall

x64Core

thank you jochen, But I want to avoid the runtime library :P I going to see MASMbasic

TouEnMasm


"0.12"
Just a floating point number.You can use strtofloat or floattostr functions who are in the masm32 lib.
There is also a function in the sdk,I don't remember what is it.

Fa is a musical note to play with CL

jj2007

Quote from: RHL on October 19, 2012, 09:26:05 AM
thank you jochen, But I want to avoid the runtime library :P I going to see MASMbasic

Try this:

include \masm32\MasmBasic\MasmBasic.inc   ; download
  Init
  Recall "MyFourLines.txt", My$()   ; read a complete text file into a string array
  push eax        ; put the line counter into a handy variable called "stack"
  Dim MyReal10(eax) As REAL10   ; for further processing (REAL4 or REAL8 would be enough, of course)
  xor ecx, ecx
  .Repeat
         ; xmm7 is safe on Win7-64 systems; any other Real4 or Real8 variable will be OK, too:
         MovVal f:xmm7, My$(ecx)   ; xmm regs can be interpreted as integer or float; use f: for floats
         mov esi, My$(ecx)   ; you can use a non-volatile reg, if you need the string read-only
         MovVal MyReal10(ecx), esi
         Print Str$("Line %i:", ecx), Tb$, "[", esi, "] converted to ", Str$(f:xmm7), Tb$, " - as Real10: ", Str$(MyReal10(ecx)), CrLf$
         inc ecx
  .Until ecx>=stack
  pop eax          ; get the counter back
  Inkey Str$("\n%i lines converted", eax)
  Exit
end start

raymond

Quote from: RHL on October 19, 2012, 08:36:43 AM
hey guys what is up?  :biggrin:
I need a bit of help please, I have a txt file with these lines:


0.12
0.45
1.80
20.01

so, how can I have theses values into a variable? I have tried do it with FPU instructions but without success, well, I have no many experience with FPU instructions :P some reference? code? or website  :biggrin: thanks!

It really all depends on what you want to do with those numbers. For example,
- If you are satisfied with only two decimal digits of precision (such as keeping track of your checking account), you can simply treat all the numbers as integers without the decimal delimiter (i.e. pennies) instead of dollars and cents (or whatever). Additions and substractions are easy but multiplications and divisions need special attention (see the following).

- If you could need a few more decimal digits of precision, you could use fixed point math; see http://www.ray.masmcode.com/fixmath.html as a start.

- If you really need the standard floating point format and don't want to use external library functions, the conversion from ASCII to float can be done relatively easily (the opposite is much more difficult).
Whenever you assume something, you risk being wrong half the time.
https://masm32.com/masmcode/rayfil/index.html