flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [fasmg] uninclude file

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 02 Mar 2017, 17:37
Let's say I have a bunch of macros in include file and I want to allow or disallow them (trigger) in different parts of source code.
Code:
enable options    ;macro

. . . do stuff from .inc file

disable options

. . . doing stuff generates error Illegal instruction

enable options

... do stuff gain
    

What would be the best way of doing it? I thought of adding "if options = enabled" check to each macro, but if the number grows, its not very convenient and slows things down
Post 02 Mar 2017, 17:37
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8405
Location: Kraków, Poland
Tomasz Grysztar 02 Mar 2017, 18:24
You could try to use separate namespaces for some macro sets:
Code:
include '8086.inc'

namespace i386
        include '80386.inc'
end namespace

        mov     ah,4Ch
        int     21h

namespace i386
        bsf     eax,ebx
end namespace

        bsf     eax,ebx ; error    
But this does not allow to freely mix and match and also it interferes with the accessibility of label definitions.

The more flexible option would be to somehow alter how the macros are defined:
Code:
macro require? option

        macro macro?! declaration&
                esc macro declaration
                if ~ option
                        err 'illegal instruction'
                end if
        end macro

end macro

macro end?.require?
        purge macro?
end macro


require SOME_OPTION

        macro instruction
                db 0
        end macro

end require    
But, since redefining crucial fasm's directives is actually a risky business, perhaps the best option is to use a custom constructions, like a meta-definitions, to define actual instructions. A nice example of such approach are the ez-80 macros.
Post 02 Mar 2017, 18:24
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 13 Mar 2017, 22:51
I just came up with the following idea for defining CPU architectures:
Code:
CPU_UNDEFINED = 0
CPU_8086      = 1
CPU_ARM       = 2

define __cpu__
__cpu__.family = CPU_UNDEFINED

macro cpu? arg
  if __cpu__.family <> CPU_UNDEFINED
    end namespace
  end if
  __cpu__.family = CPU_UNDEFINED
  match =8086, arg
    __cpu__.family = CPU_8086
    namespace x86
  else match =arm?, arg
    __cpu__.family = CPU_ARM
    namespace arm
  end match
end macro

postpone ?
  end namespace
end postpone
    

and all instructions macros wrapped in corresponding namespace.

All labels will be addressed in the architecture namespace, so should not be the problem. But could there be any other issues with such approach? I haven't tested it much, yet
Post 13 Mar 2017, 22:51
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.