flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Problem with nested macros

Author
Thread Post new topic Reply to topic
Jin X



Joined: 06 Mar 2004
Posts: 133
Location: Russia
Jin X 17 Jul 2023, 17:41
Code:
; Single-line if-then (multiple instructions for true branch is allowed)
macro   ifdo    cond*, [true*]
{
  common
    if cond
  forward
                true
  common
    end if
} ; ifdo

; Single-line if-then[-else] (multiple instructions for false branch is allowed)
macro   ifel    cond*, true*, [false]
{
  common
    if cond
                true
    else
  forward
                false
  common
    end if
} ; ifel

x = 1
y = 1

; ok
ifdo x, \
  <ifel y, <mov ax,bx>, <mov cx,dx>>

; ok
ifel x, \
  <ifdo y, <mov ax,bx>>, \
  <mov cx,dx>

; error
ifdo x, \
  <ifdo y, <mov ax,bx>>

; error
ifel x, \
  <ifel y, <mov ax,bx>, <mov cx,dx>>    
Why? Whats's wrong? How to solve the problem?
Post 17 Jul 2023, 17:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20066
Location: In your JS exploiting you and your system
revolution 17 Jul 2023, 18:59
To have a macro instantiate itself you have to redefine the macro within itself.

There is an example of nesting macros in the fasm download in win32ax.inc
Post 17 Jul 2023, 18:59
View user's profile Send private message Visit poster's website Reply with quote
Dima1205



Joined: 02 Jul 2023
Posts: 22
Location: Russian, Moscow
Dima1205 01 Aug 2023, 18:22
Тут 2 варианта. Первый условие на препроцессоре, и это тогда надо писать через match any, val { any}. Это я использовал в своём макропакете.
Второй вариант, это реализация строчного условия if else end if и это тоже нужно писать по другому.
Какой вариант интересен?

_________________
Best regards, Dmitry
Post 01 Aug 2023, 18:22
View user's profile Send private message Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 133
Location: Russia
Jin X 04 Aug 2023, 12:14
Dima1205, я бы на оба посмотрел.
Post 04 Aug 2023, 12:14
View user's profile Send private message 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.