flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > Repeat instruction in macro, according to macro parameter

Author
Thread Post new topic Reply to topic
alorent



Joined: 05 Dec 2005
Posts: 201
Repeat instruction in macro, according to macro parameter
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: 14790
Location: Lost in translation

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: 201
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: 14790
Location: Lost in translation
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: 2112
Location: Usono (aka, USA)

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: 14790
Location: Lost in translation
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.