首页 > 解决方案 > 汇编代码的预处理不起作用(#if #else #endif)

问题描述

这是汇编代码bootcode.S

        .section boot, "ax", %progbits

get_intid:
        #if INTGRP==NSG1
            #warning taking NSG1
                mrs     x0, s3_0_c12_c12_0
        #else
            #warning taking G0
                mrs     x0, s3_0_c12_c8_0
        #endif
                ret
        .end

现在我想做预处理,以便根据变量INTGRP(NSG1或G0),在“.S”文件中选择相应的行,并将结果写入“.s”文件。
当我尝试gcc -E -DINTGRP=G0时,它总是选择第二行。实际上它与 -D 选项无关。那么我应该如何给出命令以使#if 部分变为真呢?

ADD:
从评论中,我意识到出了什么问题。所以正确的方法是:

        .section boot, "ax", %progbits
#define G0 0
#define NSG1 1

get_intid:
#if INTGRP==NSG1
            #warning taking NSG1
                mrs     x0, s3_0_c12_c12_0
#else
            #warning taking G0
                mrs     x0, s3_0_c12_c8_0
#endif
                ret
        .end

并使用命令

cc -E -DINTGRP=0 bootcode.S -o bootcode.s

或者

cc -E -DINTGRP=1 bootcode.S -o bootcode.s

谢谢您的帮助!

标签: assemblyc-preprocessorpreprocessor-directive

解决方案


推荐阅读