flat assembler
Message board for the users of flat assembler.

Index > Main > Can someone explain this little example please?

Author
Thread Post new topic Reply to topic
Diode



Joined: 04 Jan 2005
Posts: 15
Diode

eq (like all other preprocessor operators) can also work with blank arguments. That means, for example, that if eq is true, and if 5 eq is false etc. Example macro:

macro mov dest,src,src2
{
if src2 eq
mov dest,src
else
mov dest,src
mov src,src2
end if
}


I copied that from actual fasm documentation, but there is little actual explanation of the code. Could someone provide an explanation for this code?

Also, I have a question about this following syntax:

macro item type,value
{
if type eq BYTE
db value
else if type eq WORD
dw value
else if type eq DWORD
dd value
else if type eq STRING
db value,0
end if
}
item BYTE,1
item STRING,'aaaaaa'


Type and value obviously store values. Now, my second question is, are type, and value variables, or are they variable types? This is confusing.

Up to this point, I've understood everything, and I tried to figure it out by myself without actually posting a topic about it, but I just don't get these parts yet.

If anyone could help me out, I'd appreciate it.

- Diode

_________________
Mac for productivity. Unix for development. Windows for solitaire.
Post 14 Jan 2005, 01:20
View user's profile Send private message Reply with quote
Diode



Joined: 04 Jan 2005
Posts: 15
Diode
Even though I don't get the previous examples I posted above, I have understood (for the most part) the code examples he gives in his fasm tutorial.

However, for some reason, I get the feeling that he delved right into explaining fasm somewhere in the middle, instead of at a beginning that I feel comfortable starting at.

Does anyone have any advice?

Thanks,
- Diode

_________________
Mac for productivity. Unix for development. Windows for solitaire.
Post 14 Jan 2005, 01:42
View user's profile Send private message Reply with quote
bogdanontanu



Joined: 07 Jan 2004
Posts: 403
Location: Sol. Earth. Europe. Romania. Bucuresti
bogdanontanu
The above things are MACROs
A macro will generate a piece of code each time it is used based on some rules.
For example dest, src and src2 are formal parameters there.
When you use the macro almost anything could be used instead of them: eax,ebx,ecx,[esi],variable_address etc
if, else, endif are conditional compile directives

So to explain that macro:
IF there is a non parameter src2 (because it could be left blank) THEN
;we do generate a simple single instruction:
mov dest,src1
ELSE
;we do generate 2 instructions:
mov dest,src
mov src,src2
ENDIF

Simple isnt it?

For the seccond macro again the type and value could be everything but it is more likely (by the names and useage) that both parameters are required and that the first parameter reflects the type of the seccond.

So it is a case like statement depending on the type the data that will be defined.
Note that a zero is appended at the end of the string as required by the null terminating strings conventions while all others are just defined acordingly to their type/size
Post 14 Jan 2005, 09:08
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.