News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

to represent an integer as a floating-point number

Started by Mikl__, August 20, 2018, 12:40:58 AM

Previous topic - Next topic

Mikl__

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?

nidud

#1
deleted

Mikl__

Hi, nidud!
It is not known what integer will appear in EAX-register

nidud

#3
deleted

hutch--

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".

RuiLoureiro

#5
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 ?
             

Siekmanski

Creative coders use backward thinking techniques as a strategy.

nidud

#7
deleted

felipe

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:

Mikl__