flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Integer to Float |
Author |
|
Madis731 20 Sep 2009, 16:10
Maybe I don't know what you are asking exactly, but I think that the solution is simpler than you imagine.
Code: WIDTH equ 16.0 SIZE equ 256.0 Other consideration might be to define them as integer like you are doing now, but convert them on the fly. Code: A dd 16 B dd 256 mov eax,[A] imul eax,[B],17 mov [A],eax add eax,1 mov [B],eax ;Now, when you want floats: fild [A] ;Load int, fild [B] ;but use as float fmulp ;like here fst [A] ;you can store that into the same space ;[---] ;Later you can take the float and turn it back as easily: fld [A] fist [A] |
|||
20 Sep 2009, 16:10 |
|
Tomasz Grysztar 20 Sep 2009, 17:39
The problem here arises from the fact that fasm is not able to do assembly-time floating-point calculations.
It may be possible to write a macro for this (int2float), however. You would have to scan for the highest set bit in the (positive) integer number, set the exponent field appropriately, and fill the mantissa bits with the bits just below this highest bit. |
|||
20 Sep 2009, 17:39 |
|
Madis731 21 Sep 2009, 07:27
I first thought about doing something like:
Code: macro int2float i { dd i#.0 } but it obviously doesn't work. One needs to do something like: Code: macro int2float i { s=(i) and 80000000h if s=80000000h b=(not i +1) and 07FFFFFFFh else b=(i) and 07FFFFFFFh end if bitscan b e=(bc+127) shl 23 m=(b shl (23-bc)) and 07FFFFFh dd s + e + m } macro bitscan b { bc=0 c=b if b=0 bc=0 else repeat 30 c=c shr 1 if c<>0 bc=bc+1 end if end repeat end if } int2float -1234 dd -1234.0 EDIT: Just as Tomasz described, I found a VHDL-lab PDF - https://www.fh-muenster.de/el-labor/downloads/vhdlversuch4.pdf |
|||
21 Sep 2009, 07:27 |
|
Mercury Knight 23 Sep 2009, 02:12
Hey Thanks!
That's exactly what I needed. You just saved me from having to do the work myself lol! Now I can get back to work here! |
|||
23 Sep 2009, 02:12 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.