本文介绍了如何在编译时检测NASM中的体系结构以使x64和x86都具有一个源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在nasm中寻找一些预处理器功能,该功能将允许为x86和x64体系结构使用一个源代码.

I am looking for some preprocessor functionality in nasm that would allow having one source code for both x86 and x64 architectures.

我的意思是与ifdef some_constant相似.就像C预处理器一样,如果它想检测是在Windows还是Linux上编译的,就使用它.

I mean something in the vein of ifdef some_constant. Like C preprocessor uses if it wants to detect say if it's compiled on Windows or Linux.

我知道nasm标志.我用它们.我只想拥有完全相同的源代码,并期望预处理器根据这些标志正确处理它.我将ifdef ... else用于堆栈操作,等等,使两种架构的核心代码相同.

I know about nasm flags. I use them. I just want to have the very same source code and expect preprocessor to handle it correctly based on those flags. I'd use ifdef ... else for stack operations and so one, having the core code same for both architectures.

推荐答案

__OUTPUT_FORMAT__

__OUTPUT_FORMAT__

http://www.nasm.us/doc/nasmdoc4 .html#section-4.12.6

%ifidn __OUTPUT_FORMAT__, win32 
  %define NEWLINE 13, 10 
%elifidn __OUTPUT_FORMAT__, elf32 
 %define NEWLINE 10 
%endif

这篇关于如何在编译时检测NASM中的体系结构以使x64和x86都具有一个源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 07:18