汇编代码中常数的UL后缀

最近遇到了一个小问题,记录一下。
问题:对于低版本的汇编器,在汇编代码中对常数使用UL后缀会报错。
1)汇编代码

$ cat main.S
.macro Test name feat
    mov %rcx, \feat
    pop %rcx
    pop %r11
    jmp \name
.endm

1:
    nop

Test 1 (1UL<<0)

1)对于 2.27 版本的汇编器

$ as --version
GNU 汇编器 version 2.27-44.base.el7
Copyright (C) 2016 Free Software Foundation, Inc.
...
$ as main.S -o main.o
main.S: Assembler messages:
main.S:11: 错误:found 'L', expected: ')'
main.S:11: 错误:junk `L<<0)' after expression

2) 对于 2.30 版本的汇编器

$ as --version
GNU 汇编器 version 2.30-73.el8
Copyright (C) 2018 Free Software Foundation, Inc.
...
$ as main.S -o main.o
$

3)其他解决方案
如果不项更换汇编器,可以参考这篇博客上给出的解决方案
根据不同的环境,定义不同的_UL() 宏

#if defined(__ASSEMBLER__)
 
#if !defined(_UL)
#define _U(x) x
#define _L(x) x
#define _UL(x) x
#endif /* !defined(UL) */
 
#else
 
#if !defined(_UL)
#define _U(x) x ## U
#define _L(x) x ## L
#define _UL(x) x ## UL
#endif /* !defined(UL) */
 
#endif /* defined(__ASSEMBLER__) */

使用 _UL() 宏

#define PTEHI_V (_UL(0x80000000))
#define PTEHI_VSID_MASK (_UL(0x7FFFFF80))




参考资料:
1. http://www.tentech.ca/2010/11/pre-processed-assembler-and-c-integer-literals/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值