Could you tell me why this simple code reports error: "expression is not simple or relocatable"? And how to fix that?

;----
; a.asm

extern a1    ; external label

b1:

b2 dd (b1 - a1)  ; ===> this causes the bug
;---



I compiled it with command: "nasm -f elf a.asm"

Many thanks
J
Posted on 2008-01-31 23:09:53 by junkoi
The macro engine in masm won't perform math apon data variables, only with constants.
Does the external label describe defined data, or a constant?
Posted on 2008-02-01 00:07:46 by Homer

The macro engine in masm won't perform math apon data variables, only with constants.


Actually I use NASM, not masm.


Does the external label describe defined data, or a constant?


The label is code, not data.

Do you have any idea how to fix it?

Thanks.
Posted on 2008-02-01 00:12:36 by junkoi

The label is code, not data.

Do you have any idea how to fix it?

Thanks.


Yeah, do your calculations at run time, since an external label/address has no definite numerical constant until link/run time.
Posted on 2008-02-01 00:27:23 by SpooK


The label is code, not data.

Do you have any idea how to fix it?

Thanks.


Yeah, do your calculations at run time, since an external label/address has no definite numerical constant until link/run time.


Can I asks nasm to delay to assign the value until link time? And is it possible to ask linker to do that instead of compiler?

Thanks,
J
Posted on 2008-02-01 00:49:12 by junkoi
;----
; a.asm

extern a1    ; external label

b1:

b2 dd 0

; Somewhere in your code section
mov eax, b1 ; EAX = B1
sub eax, a1 ; EAX = EAX - A1
mov b2, eax ; B2 = EAX
;---
Posted on 2008-02-01 17:51:09 by Synfire

Can I asks nasm to delay to assign the value until link time? And is it possible to ask linker to do that instead of compiler?

That depends on whether or not the ELF format supports more than simple address relocation.
If it doesn't, there's no way for the assembler to delay it.
Posted on 2008-02-09 16:21:29 by tenkey