flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Preprocessor fun with arithmetic

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17667
Location: In your JS exploiting you and your system
revolution
Some basic atirthmetic using the preprocessor.
Code:
macro pre_mul result,x,y {
     match xx yy,x y {
              result equ xx
               rept xx {
                      match w,result {
                               rept yy j:w {
                                      result equ j
                                \\\\}
                      \\\}
                \\}
  \}
}
macro pre_div result,remainder,x,y {
     match xx yy,x y {
              remainder equ 0
             result equ 0
                rept xx {
                      pre_inc remainder,remainder
                 match t,remainder {
                            match =t,yy {
                                  pre_inc result,result
                                       remainder equ 0
                             \\\\}
                      \\\}
                \\}
  \}
}
macro pre_add result,x,y {
       match xx yy,x y {
              rept yy j:xx {
                     result equ j
                \\}
  \}
    pre_inc result,result
}
macro pre_sub result,x,y {
  match xx yy,x y {
              result equ xx
               rept yy {
                      pre_dec result,result
               \\}
  \}
}
macro pre_inc result,x {
 match xx,x {
           rept 2 j:xx {
                      result equ j
                \\}
  \}
}
macro pre_dec result,x {
 match xx,x {
           rept xx j:0 {
                      result equ j
                \\}
  \}
}    
Post 23 Dec 2007, 13:06
View user's profile Send private message Visit poster's website Reply with quote
wht36



Joined: 18 Sep 2005
Posts: 106
wht36
Brilliant!! Exactly what I needed! Many thanks!
The ability to do maths with the preprocessor makes macros very powerful indeed!
Post 24 Dec 2008, 14:38
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
The inability of fasm's preprocessor to do integer arithmetics natively is quite a serious flaw, and since my plans for fasm 2.0 (which was supposed to have no separate preprocessor, so that macros would use assembly-time features, including expression calculating and forward-referencing) are now not likely to be realised in any near future, I'm considering adding a "precalc" directive in 1.69 development line. This would be something like:
Code:
define a 3
define b 4
precalc c a*b
rept c ; making symbolic constant to be allowed as REPT counter is another good feature to add
{
  ; repeated 12 times
}
    

And adapting fasm's expression parser and calculator to be used outside of parser/assembler scope would also make possible to implement a calculator feature in FASMD, so I'd get two nice things implemented at once this way. Yeah, it's definitely on my TODO list for 1.69.x line.
Post 30 Mar 2009, 16:51
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: 17667
Location: In your JS exploiting you and your system
revolution
So what operations will you support? */+- I think we can expect of course, but what about shl, xor and/or FP versions of */+-? Brackets?
Post 30 Mar 2009, 16:58
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
This would be the very same expression calculator, that is called by the assembler, thus all its operations would be allowed - well, except for the ones that do not work with pure integer values, like RVA or PLT.
As as I wrote above, I just plan to adapt this routine so that it will be possible to use it outside of parser/assembler modules.
Post 30 Mar 2009, 17:03
View user's profile Send private message Visit poster's website Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
buzzkill
Tomasz Grysztar wrote:
... since my plans for fasm 2.0 are now not likely to be realised in any near future...


Just curious, but why are these plans on hold? Also, by implementing a temporary solution now, wouldn't you either force yourself to keep supporting that, or force users of this solution to modify their programs when 2.0 comes around? I think, in general, it may be better to wait a little longer, and then get a complete, integrated solution, than to add a temporary workaround right now. (Unless of course you already know that your ideal solution can't be done anytime in the forseeable future).
Post 30 Mar 2009, 17:09
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
buzzkill wrote:
Also, by implementing a temporary solution now, wouldn't you either force yourself to keep supporting that, or force users of this solution to modify their programs when 2.0 comes around?

Well, it's the opposite. By implementing such solution now I would allow new possibilities while still remaining compatible with the existing. The fasm 2 project by its very design would be very incompatible syntax-wise with fasm 1.x - the design of fasm 1.x, with separate preprocessor and assembler stages, is simply not adaptable for the things I wanted to have in fasm 2.

So I guess that for people, who already use fasm 1.x and are happy with it, it may still be better to have a new features in this line, than to have a brand new assembler for which they'd have to rewrite their macros from scratch.
Post 30 Mar 2009, 17:27
View user's profile Send private message Visit poster's website Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
buzzkill
Ah OK, I didn't know that fasm2 is going to be incompatible with the current fasm. In that case you're right, of course, just add this feature Smile

Is there any documentation about fasm2? Your plans, design ideas, maybe a roadmap of sorts?
Post 30 Mar 2009, 18:12
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
I've been thinking for those few days about giving here some short summary of my fasm 2 ideas... But then I got a new one: I think it would be a nice topic to cover in the official part of the fasmcon this year. I'm going to prepare such talk for this event.
Post 02 Apr 2009, 09:58
View user's profile Send private message Visit poster's website Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen
Great, Tomasz is gonna give a talk! Smile
Post 02 Apr 2009, 10:54
View user's profile Send private message Visit poster's website Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
buzzkill
Tomasz Grysztar wrote:
I've been thinking for those few days about giving here some short summary of my fasm 2 ideas... But then I got a new one: I think it would be a nice topic to cover in the official part of the fasmcon this year. I'm going to prepare such talk for this event.


It would be nice if you could also post a transcription of this after fasmcon for those of us that can't attend, so we also know what you're up to Wink
Post 02 Apr 2009, 15:12
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
I hope we manage to set up the online conference, as on the previous events.
Post 02 Apr 2009, 15:34
View user's profile Send private message Visit poster's website Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
buzzkill
OK that's fine too, it's just that I prefer reading to watching video, that's why I asked for a transcription.
Post 02 Apr 2009, 17:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17667
Location: In your JS exploiting you and your system
revolution
buzzkill: Unless you have some really smart piece of software that can auto-transcribe then I think you have just volunteered to be the official fasmcon transcriber. Thanks for the willingness to help.

Wink
Post 02 Apr 2009, 17:26
View user's profile Send private message Visit poster's website Reply with quote
buzzkill



Joined: 15 Mar 2009
Posts: 111
Location: the nether lands
buzzkill
Laughing
Post 02 Apr 2009, 17:34
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 GitHub, YouTube, Twitter.

Website powered by rwasa.