NASM - 使用位标志扩展标签
我需要设置一些标签地址/偏移量的最高位。
我尝试过:
test.nasm:
BITS 32
dw mylabel | 0x8000
mylabel:
dd 0
但是当尝试组装这个时,我得到:
nasm -f bin test.nasm
test.nasm:3: error: `|' operator may only be applied to scalar values
为什么它没有将 mylabel 视为标量值?我认为标签只是由汇编器替换为其地址(标量值)。
如果重要的话,我正在使用 nasm v 2.09.04。
预先感谢您的任何帮助。
编辑: 我已经能够使用 + 而不是 |。看起来按位运算符不适用于标签。您认为这是故意的还是错误?
I need to set the highest bit of some label address/offset.
I tried:
test.nasm:
BITS 32
dw mylabel | 0x8000
mylabel:
dd 0
But when trying to assemble this I get:
nasm -f bin test.nasm
test.nasm:3: error: `|' operator may only be applied to scalar values
Why doesn't it see mylabel as a scalar value? I thought labels are just replaced with their address (scalar value) by the assembler.
I'm using nasm v 2.09.04 if that matters.
Thanks in advance for any help.
EDIT:
I've been able to use + instead of |. It looks as if the bitwise operators don't work on labels. What do you think, is this on purpose or a bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标签是一个可重定位的值 - 它的值由链接器/加载器修改。两个标签(在同一部分中)之间的差异是一个标量值,Nasm 将使用它。
dd (mylabel - $$) | dd (mylabel - $$) | 0x80000000
我也纠正了 32 位代码中的标签是 16 位的误解。
这样做的目的是什么?
最好的,
坦率
A label is a relocatable value - its value is modified by the linker/loader. The difference between two labels (in the same section) is a scalar value, and Nasm will work with it.
dd (mylabel - $$) | 0x80000000
I fixed the misconception that a label in 32-bit code is 16 bits for ya, too.
What is it that this is intended to accomplish?
Best,
Frank
我的猜测是这是汇编器的限制,因为 nasm 是一个两遍汇编器,它很难处理“其大小取决于相关代码之后声明的符号的值的代码”。
第3.7节
My guess is it's a limitation of the assembler, because nasm is a two pass assembler it has difficulty with is "code whose size depends on the value of a symbol declared after the code in question."
http://www.posix.nl/linuxassembly/nasmdochtml/nasmdoc3.html
Section 3.7