flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > iFAQs about macros

Author
Thread Post new topic Reply to topic
ssp



Joined: 05 Mar 2007
Posts: 38
Location: India
ssp 19 Jun 2007, 02:37
I have some infrequently asked questions about macros. The questions pop-up in my mind from time to time, as and when I need something in macros.

My first few questions:

How do I do this:
Code:
.while TRUE
; blah
 .break .if eax = 10
; .blah
.endw
    

and this:
Code:
dd a,b,c,p=3,q,r,s,x=5,y=1,z=100
    


May the wisemen here help me. Amen!

_________________
From: Sandeep
Post 19 Jun 2007, 02:37
View user's profile Send private message Yahoo Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 19 Jun 2007, 03:02
Unfortunately there is no .break provided. However is possible to workaround this problem
Code:
.while TRUE 
; blah 
.if eax = 10 
  jmp .exitWhile
.endif
; .blah 
.endw
.exitWhile:    


As for the second code can you explain more detailed what you want? Perhaps define the dword and assign the value to the assembly-time variable at the same time? If that is the case then this should do the work
Code:
macro dd [value]{
forward
  if 1
  match var==val, value
  \{
    dd val
    var = val
  else
  \}
    dd value
  end if
}    


Example
Code:
a = 1
b = 2
c = 3
p = 4
q = 5
r = 6
s = 7


dd a,b,c,p=3,q,r,s,x=5,y=1,z=100

display a+'0', ';', p+'0', ';', x+'0'    


Displays "1;3;5"
Post 19 Jun 2007, 03:02
View user's profile Send private message Reply with quote
ssp



Joined: 05 Mar 2007
Posts: 38
Location: India
ssp 19 Jun 2007, 04:33
Thanks LocoDelAssembly.
That was very childish of you!

I myself could have figured out the first alternative suggested by you,
but I wanted to do it exactly as I wrote.

The second one is nice, but it would be nicer if it were included in
the standard macros.

_________________
From: Sandeep
Post 19 Jun 2007, 04:33
View user's profile Send private message Yahoo Messenger Reply with quote
ssp



Joined: 05 Mar 2007
Posts: 38
Location: India
ssp 20 Jun 2007, 02:41
I did the following and it works:
Code:
; inside if.inc
macro .while [arg]
{
  common
  local ..while
  __WHILE equ ..while
  local ..endw
  __ENDW equ ..endw
  .break equ jmp ..endw ; Updated.
  __WHILE:
  JNCOND __ENDW,arg
}

; and now I can do this
        mov ebx, 10
        .while ebx
                invoke MessageBox,0,'Ping!',0,0
                dec ebx
                .if ebx < 8
                        .break
                .endif
        .endw
    


fasm is great!
Post 20 Jun 2007, 02:41
View user's profile Send private message Yahoo Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 20 Jun 2007, 03:06
In that way if you have nested .while loops, any .break occurence will jump to the last .endw issued

Code:
.while ebx
  .
  .
  .break ; ok
  .
  .
    .while eax
    .
    .
    .endw
  .
  .
  .break ; bad, jumps to the end of the ".while eax"
  .
  .
.endw    


Aditionally, after defining a .while loop, .break becomes always available and jumps to the last .endw issued

In case you want to add real ".break .if cond" support you can use match directive to automatically convert it to .if cond/.break/.endif.

Add to .endw macro "restore .break"
Post 20 Jun 2007, 03:06
View user's profile Send private message Reply with quote
ssp



Joined: 05 Mar 2007
Posts: 38
Location: India
ssp 20 Jun 2007, 03:29
Thanks LocoDelAssembly for your suggestions.
I'll try to improve it and make it nestable.
Post 20 Jun 2007, 03:29
View user's profile Send private message Yahoo Messenger Reply with quote
ssp



Joined: 05 Mar 2007
Posts: 38
Location: India
ssp 21 Jun 2007, 06:14
I did this in IF.INC:
Code:
macro .while [arg]
{
  common
  local ..while
  __WHILE equ ..while
  local ..endw
  __ENDW equ ..endw
  .break equ jmp ..endw
  .continue equ jmp ..while
  __WHILE:
  JNCOND __ENDW,arg
}

macro .endw
{
  jmp __WHILE
  __ENDW:
  restore __ENDW
  restore __WHILE
  restore .break
  restore .cotinue
}
    

And now I have nestable .break and .continue Cool
Post 21 Jun 2007, 06:14
View user's profile Send private message Yahoo Messenger Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 21 Jun 2007, 06:27
Perhaps this could get checked and go into the list of unofficial fasm addon macros.
Post 21 Jun 2007, 06:27
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger 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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.