flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > (?) need help to understand

Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

I am certainly not an expert about macros, but I'm amazed by this below.
yes, I know, these examples do not make much sense,
it's just a theoretical reflection in the context of Wink development.

main question:
I don't understand why 1B does compile, and 2B does not.
Because the difference between both cases is the same ( \{ \} ---> { } )

secondary question:
1B does compile, but the result is only 2 bytes, why ?

Again, macros are not my cup of tea, but i need to understand this.
thank you.
Code:
use32
;1A

rept 2 x {

mov eax,eax

struc myS#x \{ dd x \}

data#x myS#x

}
;Result: does compile/12 bytes
;mov eax,eax    ;2
;dd 1           ;4
;mov eax,eax    ;2
;dd 2           ;4
;------------------------------------------------
;1B

rept 2 x {

mov eax,eax

struc myS#x { dd x } ;differences between 1A and 1B: \{ \} ---> { }

data#x myS#x

}
;Result: does compile/2bytes (not "incomplete macro" like 2B)
;mov eax,eax    ;2
;================================================
;2A

rept 2 {

mov eax,eax

rept 2 \{ mov ebx,ebx \}

}
;Result: does compile/12 bytes
;mov eax,eax    ;2
;mov ebx,ebx    ;2
;mov ebx,ebx    ;2
;mov eax,eax    ;2
;mov ebx,ebx    ;2
;mov ebx,ebx    ;2
;------------------------------------------------
;2B

rept 2 {

mov eax,eax

rept 2 { mov ebx,ebx } ;differences between 2A and 2B: \{ \} ---> { }

}
;Result: does not compile (incomplete macro)
    

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 29 Nov 2011, 17:34
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
The "{" character has no special meaning inside a macro block, only the "}" character is special in that it closes the definition of macroinstruction. The "{" character will be just put into generated macro text, like any other character (while if you want to do it with "}" you always have to escape it, otherwise it is going to be interpreted as end of the macro you're defining).

It was done this way to allow one macro to start the definition of another one, like "tmacro" example at the end of section 2.3.3 of manual.
I also already gave you some more examples (though not all are useful ones). Also the good old globals macros (which were adopted by the Fresh project) utilize this feature.
Post 29 Nov 2011, 22:58
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

thank you Tomasz for your reply.
I have read all articles! (from beginning to end) Wink
I don't understand everything, (I do my best)

So, how do you explain this?

I understand why the macro A does compile
and i understand the result of 6bytes.
But in the macro B, where is the end of the macro ?

B1? or B2? (i think B1)

if B1 is the end of macro B
then why "}"(B2) alone does not trigger an error ?

and if B2 is the end of macro B
why "2bytes" and not 6 like macro A ?

I think B1 is the end of the macro B.
In this case, the result of 2 bytes is correct.
But in this case, why B does compile ... (because B2?)

Image

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 30 Nov 2011, 01:33
View user's profile Send private message Send e-mail Reply with quote
addes3



Joined: 09 May 2011
Posts: 29
addes3
I believe B2 is being used to end the "struc" definition, which generates no code.
Post 30 Nov 2011, 19:34
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji
Quote:
I believe B2 is being used to end the "struc" definition, which generates no code.
one "}" to end "rept", and another "}" to end "struct" ?

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 30 Nov 2011, 21:21
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
ouadji wrote:
one "}" to end "rept", and another "}" to end "struct" ?
Yes. Formatting it like this may help to understand what's going on:
Code:
rept 1
{
     mov eax,eax
     struc myS
     {
       .mydata dd 1
}

       abc myS
     }    
Post 30 Nov 2011, 22:34
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji
Here is finaly the explanation I expected from the beginning of this thread! All manuals and all examples would never have given this explanation. How this macros engine works is really surprising. It will be very difficult to implement the highlighting of macros (in all cases) with this kind of nestings. Thank you Tomasz.

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 01 Dec 2011, 00:23
View user's profile Send private message Send e-mail 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.