flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Repeat instruction in macro, according to macro parameter

Author
Thread Post new topic Reply to topic
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 28 Apr 2017, 16:04
Hi,

I was wondering if I can create a macro that work like this:

MY_MACRO param

Where I generate the following:

MY_MACRO 1 ---> it will generate:

Code:
PUSH EAX
    


MY_MACRO 2 ---> it will generate

Code:
PUSH EAX
PUSH EAX
    


MY_MACRO 3 ---> it will generate:

Code:
PUSH EAX
PUSH EAX
PUSH EAX
    


MY_MACRO n ---> it will generate:

Code:
PUSH EAX
....
....
PUSH  EAX   ; this is the "n" time
    


Thanks!
Post 28 Apr 2017, 16:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20335
Location: In your JS exploiting you and your system
revolution 28 Apr 2017, 16:13
Code:
macro MY_MACRO x {
  repeat x
    push eax
  end repeat
}    
Post 28 Apr 2017, 16:13
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 28 Apr 2017, 16:59
Thanks revolution! You made my day again! Smile
Post 28 Apr 2017, 16:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20335
Location: In your JS exploiting you and your system
revolution 28 Apr 2017, 17:19
You're welcome. Macros in fasm can be tricky things. But one thing to realise here is that repeat is executed at assembly time. There is another option using rept for preprocessor time execution.
Post 28 Apr 2017, 17:19
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 02 May 2017, 00:36
revolution wrote:
repeat is executed at assembly time, rept at preprocessor time


So which stage is times?

Code:
times 3 movsb
times 4 : shr ax,1
    


It's mentioned right before repeat in the manual, so I assume they are similar.
Post 02 May 2017, 00:36
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: 20335
Location: In your JS exploiting you and your system
revolution 02 May 2017, 04:02
times is assembly time evaluation.
Post 02 May 2017, 04:02
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.