NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: ben321 on March 12, 2023, 06:16:07 AM
-
Lets say a macro included something like this:
MOV EAX,[ptrData]
That's for 32 bit code. Let's say I wanted the macro to be usable in both 32 bit and 16 bit code though, so I didn't need to write 2 separate macros. Is there like predefined constant that NASM can set, that will let you tell your macro to behave differently? For the above example, I'd want the 16 bit code to say:
MOV AX,[ptrData]
-
That's where I'd use things like #ifdefine and it's companions. Nasm doesn't write your code for you.
-
That's where I'd use things like #ifdefine and it's companions. Nasm doesn't write your code for you.
Isn't ifdefine a C instruction though? I didn't know NASM could do that. I had hoped it would. So I'd use it like this then.
#ifdefine Is16Bits
;16bit code goes here
#else
;32bit code goes here
#endif
How do I do the "Is16Bits" part though? Does NASM provide a compiler-set constant that is either defined or not defined, based on what bitness mode is currently being used?
-
I just looked it up in the manual (section 4.4.1, you will find it helpful to read the manual), and I should have said #ifdef. The code would be
#ifdef Is16Bits
;16bit code goes here
#else
;32bit code goes here
#endif
-
Nasm doc 5.3:
%if __?BITS?__ == 16
...
%elif __?BITS?__ == 32
...
%elif __?BITS?__ == 64
...
%endif