flat assembler
Message board for the users of flat assembler.

Index > Main > Macro tips

Author
Thread Post new topic Reply to topic
nmake



Joined: 13 Sep 2012
Posts: 193
nmake
I'm not very familiar with fasm macros, I try to keep regularly used and important facts in an everygrowing note.

How can I repeat something using either repeat or rept and increase a floating point number without having to resort to complex int to string macros. I have this direct3d program and I need to duplicate several cube sections to make up a very long corridor, and I use floating point constants to position the cubes, how can I repeat something and add 2.0 to the constant on each iteration?

I guess I have to use some form of int to string macros and then pad .0 to it?
Post 21 Feb 2013, 09:12
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
nmake,

Preprocessor operates with symbols (though it recognizes them as numbers when needs to). For simple cases it can help: rept 10 i:0 { dd 2#i#.0 } will generate equivalent of dd 20.0, 21.0, ..., 29.0. More generic cases probably will require assembly stage to perform compile-time floating point processing (preprocessor can join symbols but can't split them, at least directly, AFAIK).

Explain your problem, maybe it can be solved.
Post 21 Feb 2013, 11:04
View user's profile Send private message Reply with quote
nmake



Joined: 13 Sep 2012
Posts: 193
nmake
My simple problem is that I need to add 2.0 to a floating point immediate parameter that I pass to a function. Thats the whole simple problem.
Code:
invoke function,2.0    

now, invoke the same function, but with 4.0 next time, then 6.0 next time, then 8.0 next time. Repeat this 20 times over.

I used runtime floating point calculation to temporary solve it, it was just for testing purposes, building a very large stone corridor.

http://i.imgur.com/tNvDPkC.jpg
Post 21 Feb 2013, 11:32
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
nmake,

Preprocessor can perform compile-time calculations.
Code:
rept 20 % {
  rept 1 %%: %*2 \{
    invoke function, %%\#f
  \}
}    
Why don't use a loop?
Post 21 Feb 2013, 13:21
View user's profile Send private message Reply with quote
nmake



Joined: 13 Sep 2012
Posts: 193
nmake
Yes, I forgot about the escape characters.
Post 21 Feb 2013, 13:36
View user's profile Send private message 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 YouTube, Twitter.

Website powered by rwasa.