Author Topic: multiplying/dividing a positive decimal number by a positive number  (Read 33191 times)

Yuri

  • Member
  • **
  • Posts: 179
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #60 on: March 19, 2015, 03:29:32 AM »
I doubt it's a question of format. The code works correctly for me with just "%g".
Quote
---------------------------
Result
---------------------------
9980.69
---------------------------
ОК   
---------------------------

shankle

  • Member
  • ****
  • Posts: 868
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #61 on: March 24, 2015, 02:18:49 AM »
        3-23-2015
My knowledge about FPU is hovering just above Zero.

    fixed dq  12.0
    n4    dq  0
    buf7  db  8 DUP (0h)
    Value db  '.043'

How do I put .043 into the ST0 FPU register
The result from Fild is incorrect

    fild D[Value] ;load Value into the ST0 register on the fpu stack
    fdiv Q[fixed] ; divide it by 12.0 directly from memory
    fstp Q[n4]    ; pop the results off the stack to memory
    invoke msvcrt:sprintf_s,addr buf7,sizeof buf7,\
                   "%g",[n4]

    invoke TextOut, [hdc],200,425,addr buf7,8
   

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #62 on: March 24, 2015, 02:31:53 AM »
My knowledge about FPU is hovering just above Zero.

Reading Ray's tutorials may help.

FORTRANS

  • Member
  • *****
  • Posts: 1238
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #63 on: March 24, 2015, 03:21:50 AM »
Hi,

   FILD is to load from an integer variable.  FLD loads from a real
valued variable.

Code: [Select]
Fixed   DW      12
Real    DD      12.0

        FILD    [Fixed]
        FLD     [Real]

   Both end up with 12.0 in the FPU.  But look at a listing to see
some differences.

Regards,

Steve N.

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #64 on: March 24, 2015, 03:37:54 AM »
Code: [Select]
Value db  '.043'
loading it into the FPU is actually the easy part
your big problem here is converting an ASCII string into a float

now, there are a few ways to go about this
one way is to use the masm32 library StrToFloat function

Code: [Select]
    .DATA

r08Value REAL8 ?
Value db  '.043'

    .CODE

    INVOKE  StrToFloat,offset Value,offset r08Value

    fld     r08Value     ;load REAL8 into FPU ST(0)

the StrToFloat function only supports REAL8 types

i guess, for GoAsm, the "offset" syntax is a little different

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #65 on: March 24, 2015, 03:42:55 AM »
another way would be to convert "0.043" to a fixed-point integer of 43
load the integer and divide it by a constant real of 1000.0

still another way might be to load it using BCD math - i'm not very familiar with that
but, Ray's tutorials and libraries might help

shankle

  • Member
  • ****
  • Posts: 868
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #66 on: March 24, 2015, 12:11:29 PM »
So where is Ray's tutorial?
I read about the lib from 2012 and it had errors.
Have they been fixed?
I will gladly give it a read if I can find it.

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #68 on: March 24, 2015, 01:11:35 PM »
also, visit the main page - scroll down to the bottom

http://www.ray.masmcode.com/

rrr314159

  • Member
  • *****
  • Posts: 1378
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #69 on: March 24, 2015, 02:00:51 PM »
this tutorial was my "bible" learning the FPU - thanks Raymond!
I am NaN ;)

shankle

  • Member
  • ****
  • Posts: 868
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #70 on: March 25, 2015, 12:53:12 AM »
Thanks guys,
I should have known about this weeks ago.
In my short perusal so far I think "fpulib" is a gold mine.

BUT, FpuAtoFl shows an error for this instruction.
So I need the equivalent of Raymonds tutorial for GoAsm.
I don't think it exists. :(

And yes, Thanks Raymond :biggrin:
« Last Edit: March 25, 2015, 03:10:21 AM by shankle »

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #71 on: March 25, 2015, 07:04:57 AM »
FpuAtoFl sounds like one of Ray's library functions - not the same as an instruction
also - Ray's code is probably 32-bit
you may have to adapt to 64-bit code

Yuri

  • Member
  • **
  • Posts: 179
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #72 on: March 25, 2015, 04:29:46 PM »
shankle
What happened to _atodbl? Did it stop working for you?

Code: [Select]
DATA SECTION

fixed dq  12.0
n4    dq  0
buf7  db  16 DUP (0h)
Value db  '.043',0

CODE SECTION

Start:
    invoke msvcrt:_atodbl, addr buf7, addr Value
    fld Q[buf7]
    fdiv Q[fixed]
    fstp Q[n4]
    invoke msvcrt:sprintf_s, addr buf7, sizeof buf7, "%g", [n4]
    invoke user32:MessageBoxA, 0, addr buf7, "Result", 0

Quote
---------------------------
Result
---------------------------
0.00358333
---------------------------
ОК   
---------------------------

shankle

  • Member
  • ****
  • Posts: 868
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #73 on: March 26, 2015, 12:02:28 AM »
Sorry Yuri,
Nothing wrong with atodbl. Guess I thought Ray's stuff would
replace Msvcrt. So if I understand correctly GoAsm will not
support Rays tutorial and I must use Microsofts Msvcrt:xxxxx.
Sorry for the confusion.

Yuri

  • Member
  • **
  • Posts: 179
Re: multiplying/dividing a positive decimal number by a positive number
« Reply #74 on: March 26, 2015, 01:32:55 AM »
The tutorial describes how the FPU works, so it's definitely useful. But fpu.lib is 32-bit, so you can only use it in 32-bit code, like this:

Code: [Select]
DATA SECTION

DEST_MEM8   EQU   200000h
SRC1_REAL8  EQU   20000h
SRC2_DIMM   EQU   800h
fixed dq  12.0
n4    dq  0
buf7  db  16 DUP (0h)
Value db  '.043',0

CODE SECTION

Start:
    invoke fpu.lib:FpuAtoFL, addr Value, addr buf7, DEST_MEM8
    fld Q[buf7]
    fdiv Q[fixed]
    fstp Q[n4]
    invoke fpu.lib:FpuFLtoA, addr n4, 8, addr buf7, SRC1_REAL8 | SRC2_DIMM
    invoke user32:MessageBoxA, 0, addr buf7, "Result", 0
    ret

Quote
---------------------------
Result
---------------------------
 0.00358333
---------------------------
ОК   
---------------------------