1

I have a piece of nasm assembly code which I want to be yasm compatible, but running the assembler on it gives errors on a couple of nasm-specific macros and includes, mostly related to the conditional

%if __BITS__ == 32

Where __BITS__ is the current bit mode.

Does YASM have equivalent functionality, or any other way to follow a code path depending on the bit mode?

Matt O
  • 1,336
  • 2
  • 10
  • 19
  • You could always define __BITS__ yourself on the command line when compiling code. example: `yasm -D__BITS__=32 file.asm`, `yasm -D__BITS__=16 file.asm` etc. – Michael Petch Sep 29 '15 at 01:20

1 Answers1

1

You should be able to define a macro to use instead of bits, like this (untested):

%macro myBits 1
    bits %1
    %assign __BITS__ %1
%endmacro

Of course in this case you'd have to replace every occurance of bits 16, bits 32 and bits 64 in your source code with the equivalent myBits macro.

Note that I'm not quite sure how bits is implemented in YASM. It might be that it is a macro itself (that internally relies on a lower level directive like [bits]). In this case you may be able to redefine the bits macro and avoid the need to change anything.

For source code that doesn't use the bits directive at all, I'd just define __BITS__ with the assembler's command line argument.

Brendan
  • 35,656
  • 2
  • 39
  • 66