문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top