NASM - Extending label with bit flag
I need to set the highest bit of some label address/offset.
I tried:
test.nasm:
BITS 32
dw mylabel | 0x8000
mylabel:
dd 0
B开发者_运维知识库ut 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?
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
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
精彩评论