flat assembler
Message board for the users of flat assembler.

Index > Main > Is it possible to insert code from later in the file?

Author
Thread Post new topic Reply to topic
Plue



Joined: 15 Dec 2005
Posts: 151
Plue 29 Nov 2006, 14:51
Is it possible to trick fasm into doing something like this?

Code:

<insert SymbolName here>

Macro SymbolName {
   Simple list of instructions
   ..
}

    

_________________
Roses are red
Violets are blue
Some poems rhyme
And some don't.
Post 29 Nov 2006, 14:51
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 29 Nov 2006, 15:33
unfortunatelly, no.

only with some very dirty tricks, and i am not sure about it.
Post 29 Nov 2006, 15:33
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 29 Nov 2006, 17:47
Macros cannot be forward referenced, not ever, never, no chance, not possible. Except if you rewrite fasm.
Post 29 Nov 2006, 17:47
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 29 Nov 2006, 18:00
but you can store data in variables and forward reference variables... that's what i meant with "very dirty tricks"
Post 29 Nov 2006, 18:00
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 29 Nov 2006, 18:28
This "dirty trick" is closely related to this problem: http://board.flatassembler.net/topic.php?t=5934
Post 29 Nov 2006, 18:28
View user's profile Send private message Visit poster's website Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue 29 Nov 2006, 19:17
revolution wrote:
Macros cannot be forward referenced, not ever, never, no chance, not possible. Except if you rewrite fasm.
As I said, I don't need full macro functionality, only a simple list of instructions.

It looks like what I want to do is actually possible by forward-referencing a variable from a macro and then generating the instructions from that macro. But I managed to do it some other way by buffering up all the code in between, writing the simple list of instructions without going through the buffer, and then writing the buffer. (I am writing a compiler.)

_________________
Roses are red
Violets are blue
Some poems rhyme
And some don't.
Post 29 Nov 2006, 19:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 29 Nov 2006, 20:39
Plue wrote:
As I said, I don't need full macro functionality, only a simple list of instructions.
Where did you say that?
Plue wrote:
I am writing a compiler.
Do you have a website where we can see your compiler?
Post 29 Nov 2006, 20:39
View user's profile Send private message Visit poster's website Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue 29 Nov 2006, 21:44
revolution wrote:
Plue wrote:
As I said, I don't need full macro functionality, only a simple list of instructions.
Where did you say that?
Ok, maybe I didn't say it very clearly, but:

Macro SymbolName {
Simple list of instructions < Here!!! Wink
..
}

Quote:
Plue wrote:
I am writing a compiler.
Do you have a website where we can see your compiler?
Yup! http://lasic.frac.dk/forum/

_________________
Roses are red
Violets are blue
Some poems rhyme
And some don't.
Post 29 Nov 2006, 21:44
View user's profile Send private message Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat 30 Nov 2006, 00:41
revolution wrote:
Macros cannot be forward referenced, not ever, never, no chance, not possible.
Sounds like a challenge Wink Call this file fwdmac.asm
Code:
match =1,second {
        mymacro
}

match =second,second {
        macro mymacro \{
                db "blah"
        \}

        second equ 1
        include 'fwdmac.asm'
}    
Post 30 Nov 2006, 00:41
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 30 Nov 2006, 08:03
Goplat: Very Happy good one....
Post 30 Nov 2006, 08:03
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 30 Nov 2006, 11:16
Goplat wrote:
Sounds like a challenge
I like it. Now that is really thinking outside the box.

Okay, I change my statement a little. How about this:

Macros cannot be forward referenced in a useful way, not ever, never, no chance, not possible.

Hehe, now the challenge is to make it useful ... Wink
Post 30 Nov 2006, 11:16
View user's profile Send private message Visit poster's website Reply with quote
Mr_Silent



Joined: 25 Apr 2006
Posts: 30
Mr_Silent 30 Nov 2006, 15:44
2 revolution: What is your meaning of "useful"?
Code:
.maincode fix _main
macro _main
 {
  macro tag_main {
 }
;------------------------------------------------------------------------------
.postdef fix } _post
macro _post
 {
  macro tag_post {
 }
;------------------------------------------------------------------------------
.end fix } _end
macro _end
 {
  tag_post
  tag_main
 }
;//////////////////////////////////////////////////////////////////////////////

.maincode
 zb sb1,'a','b','z','x'
 zd sd1,'a','b','z','x'

.postdef

 macro zd p1,[p2]
  \{
   \common
   label p1
   \forward
   dd p2
   \common dd 0
  \}

 macro zb p1,[p2]
  \{
   \common
   label p1
   \forward
   db p2
   \common db 0
  \}

.end
    
Post 30 Nov 2006, 15:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 30 Nov 2006, 22:45
Mr_Silent: I think your code does not address the problem of defining the macros after you instantiate it. You code defines a few macros but does not use any of them until the final ".end" statement.

Goplat posted a nice example of reassembling the same file again that simulates defining macros after they are used, but I think it is not useful in any real program. It was all in good fun and my challenge was not anything serious. I would be delighted to see a real-world working example of Goplat's idea given above.
Post 30 Nov 2006, 22:45
View user's profile Send private message Visit poster's website Reply with quote
Mr_Silent



Joined: 25 Apr 2006
Posts: 30
Mr_Silent 01 Dec 2006, 06:40
revolution wrote:
I think your code does not address the problem of defining the macros after you instantiate it.

Of course, it doesn't Very Happy . There is no such problem, Exclamation because strait fwd-ref is impossible (with current implementation of Fasm preprocessor) Exclamation , point. The only matter could be discussed here is how to "trick fasm into doing something like..." (see post 1).
Idea Very Happy Or did you want the community to find some critical bu... err... feature which will allow normal fwd-ref Question Very Happy
Post 01 Dec 2006, 06:40
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 01 Dec 2006, 12:31
Mr_Silent wrote:
Or did you want the community to find some critical bu... err... feature which will allow normal fwd-ref
Yep, I would like to see someone find a "feature". Feature finding is a hobby of mine. Wink
Post 01 Dec 2006, 12:31
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.