The MASM Forum

General => The Campus => Topic started by: Mikl__ on August 20, 2018, 12:40:58 AM

Title: to represent an integer as a floating-point number
Post by: Mikl__ on August 20, 2018, 12:40:58 AM
1. FPU push 436
fild dword ptr [esp]
fstp dword ptr [esp]
pop eax
2. integer instructions mov eax,-436
or eax,eax
jz @f
cdq ; if eax <0 then edx:=-1 else edx:=0
xor eax,edx
sub eax,edx;  eax:=|eax|
and edx,256; Sign bit
bsr ecx,eax
ror eax,cl
add eax,edx
lea eax,[eax+ecx+126]
rol eax,23;eax=0C3DA0000h=-436.0
@@:
3. SSE mov eax,436
cvtsi2ss xmm0,eax
    movd eax,xmm0
Are there other ways to solve this problem yet? (https://wasm.in/styles/smiles_s/scratch_one-s_head.gif)
Title: Re: to represent an integer as a floating-point number
Post by: nidud on August 20, 2018, 01:21:19 AM
deleted
Title: Re: to represent an integer as a floating-point number
Post by: Mikl__ on August 20, 2018, 01:30:06 AM
Hi, nidud!
It is not known what integer will appear in EAX-register (https://wasm.in/styles/smiles_s/mosking.gif)
Title: Re: to represent an integer as a floating-point number
Post by: nidud on August 20, 2018, 02:18:57 AM
deleted
Title: Re: to represent an integer as a floating-point number
Post by: hutch-- on August 20, 2018, 02:53:31 AM
MASM in 64 bit has no problems loading a floating point value into the right sized integer register, REAL4 = 32 bit, REAL8 = 64 bit but they are not integer values, they are still in floating point format. If you want integer output from floating point, use "fistp".
Title: Re: to represent an integer as a floating-point number
Post by: RuiLoureiro on August 20, 2018, 03:37:35 AM
Olá Mikl__ !
              Very well. With SSE, to convert 4 integers to real4 we may use cvtdq2ps :biggrin: . In this way
i start the elements of an allocated matrix with 1,2,3,4,5,... converted to real4 1.0,2.0,3.0,4.0,5.0,... It is used to test SSE procedures. Is there a better way ?
             
Title: Re: to represent an integer as a floating-point number
Post by: Siekmanski on August 20, 2018, 04:17:15 AM
yes, cvtdq2ps  :biggrin:
Title: Re: to represent an integer as a floating-point number
Post by: nidud on August 20, 2018, 04:48:36 AM
deleted
Title: Re: to represent an integer as a floating-point number
Post by: felipe on August 20, 2018, 04:53:34 AM
If it's just a matter of "representing" you can actually treat the integer as an ascii value and append then a ".0" to the end of the string in some buffer where it's stored. :idea:
Title: Re: to represent an integer as a floating-point number
Post by: Mikl__ on August 20, 2018, 10:08:08 AM
thank you all for the help! (https://wasm.in/styles/smiles_s/thank_you.gif)