2

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?

masterxilo
  • 2,503
  • 1
  • 30
  • 35

2 Answers2

3

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

  • The dw is supposed to store the offset (as a 16 bit value) of the mylabel-label from the beginning of the file, but it has to be extended with some flag. I'm writing the .reloc section of a win exe (PE) file/image manually. – masterxilo Dec 07 '10 at 14:49
0

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

OmnipotentEntity
  • 16,531
  • 6
  • 62
  • 96