flat assembler
Message board for the users of flat assembler.

Index > Main > Problem with rept macro...

Author
Thread Post new topic Reply to topic
polygon7



Joined: 14 Aug 2003
Posts: 62
Location: Poznan, Poland
polygon7
Hi,
i have problem with following macro:
Code:
res     equ 8

theta   equ 6.283185307179f / res
phi     equ 3.141592653589f / res

theta_array:
    rept res
    {
        dd % * theta  ; Theta array
    }

phi_array:
    rept res
    {
        dd % * phi  ; Phi array
    }    

I try to compile it, but i have error: "rept res" invalid value. How can i fix it?

_________________
best regards
p7
Post 10 Aug 2005, 02:45
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
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.
Post 10 Aug 2005, 03:20
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
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
Post 10 Aug 2005, 06:42
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
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
Post 10 Aug 2005, 07:30
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
No, "res" is not reserved.
Post 10 Aug 2005, 07:40
View user's profile Send private message Visit poster's website Reply with quote
polygon7



Joined: 14 Aug 2003
Posts: 62
Location: Poznan, Poland
polygon7
Its working, thank you Smile

_________________
best regards
p7
Post 10 Aug 2005, 11:18
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.