flat assembler
Message board for the users of flat assembler.
Index
> Main > Problem with rept macro... |
Author |
|
revolution 10 Aug 2005, 03:20
Firstly another problem you have is that FASM does not support arithmetic (*,/,+,-) with floating point values. Secondly you will need to change the first line to "res fix 8" to get a rept structure working in that way.
|
|||
10 Aug 2005, 03:20 |
|
Tomasz Grysztar 10 Aug 2005, 06:42
Generally the "repeat" and "=" should be used instead for "rept" and "equ" where calculations are involved (see manual), but - as revolution already noted, fp calculations are not supported (for portability/SSSO reasons mainly, it agrees with NASM in this aspect).
This: Code: res = 8 theta = 6.283185307179f repeat res dd % * (theta / res) end repeat is almost correct, but the calculation is performed on integers, the floating point value is by default 64-bit, thus the overflow happens. It you used: Code: theta = dword 6.283185307179f the 32-bit represenation of fp value would be generated, so "theta" would get just the 40C90FDBh value - this code would even assemble, but such calculations are certainly not what you need. It would be however possible to write some macroinstructions to perform fp operation using the integer ones. Just for the beginning, this can extract the mantissa and exponent from the 32-bit representation of floating point number: Code: macro get_fp value { virtual at 0 dd value load fp_value dword from 0 end virtual mantissa = 800000h + fp_value and 07FFFFFh exponent = (fp_value shr 23) and 0FFh - 7Fh sign = fp_value shr 31 } and this can use those components to make up the 32-bit representation of floating point value back: Code: macro store_fp name { while mantissa >= 1000000h mantissa = mantissa shr 1 exponent = exponent + 1 end while while mantissa < 800000h mantissa = mantissa shl 1 exponent = exponent - 1 end while name = (mantissa - 800000h) + (exponent+7Fh) shl 23 + sign shl 31 } I got it working this way: Code: theta equ 6.283185307179f res = 8 theta_array: repeat res get_fp theta mantissa = %*(mantissa/res) store_fp tmp dd tmp end repeat but it may loose some of the precision - the longer mantissa representation could be used to get better. Last edited by Tomasz Grysztar on 10 Aug 2005, 07:39; edited 3 times in total |
|||
10 Aug 2005, 06:42 |
|
Madis731 10 Aug 2005, 07:30
isn't "res" a reserved symbol? I wouldn't know :S
Last edited by Madis731 on 10 Aug 2005, 07:57; edited 1 time in total |
|||
10 Aug 2005, 07:30 |
|
Tomasz Grysztar 10 Aug 2005, 07:40
No, "res" is not reserved.
|
|||
10 Aug 2005, 07:40 |
|
polygon7 10 Aug 2005, 11:18
Its working, thank you
_________________ best regards p7 |
|||
10 Aug 2005, 11:18 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.