Reputation: 87371
I'm trying to compile this with nasm -f bin -o bo.bin bo.nasm
:
bits 16
cpu 8086
org 0 ; Default.
section HEADER align=1
section _TEXT follows=HEADER align=1
section CONST follows=_TEXT align=1
section CONST2 follows=CONST align=1
section _DATA follows=CONST2 align=1
section _BSS follows=_DATA nobits align=1
section HEADER
mov si, section._TEXT.start
mov di, section.CONST.start
db 0xb9 ; mov cx, ...
; bo.nasm:17: error: operand 1: expression is not simple or relocatable
dw section.CONST.start-section._TEXT.start
section _TEXT
; --- End of header.
section _TEXT
db 'FOO/'
section _DATA
db 'BARR/'
section _TEXT
db 'FOOD/'
section _BSS
v1: resb 0x1000
v2: resb 2
I'm getting this error for the dw
line:
bo.nasm:17: error: operand 1: expression is not simple or relocatable
In the dw
line I want to emit the byte size of the _TEXT section. section.CONST.start-section._TEXT.start
is an implementation detail, it can be changed. (I also tried with the .vstart
suffix instead of .start
, but it didn't help. I looked at the source code of nasm, and I couldn't find any other lables it defines.)
I need a solution which:
nasm -f bin
. Other assemblers and other output formats are not allowed.; --- End of header.
line, e.g. adding a label after db 'FOOD/'
is not allowed. (This is because I'm writing a nasm %include library, and asking the user to add labels would make it error-prone.)mov cx, di
+ sub cx, si
is not allowed, I need the result in the existing dw
. (This is because I will repace the HEADER contents with the actual file format header, which doesn't contain assembly instructions.)Upvotes: 1
Views: 800
Reputation: 87371
It looks like what I want is not possible with NASM, because NASM can't do arithmetic using labels from multiple sections. As a workaround, after adding the label text.end
to the end of the _TEXT
section, this works:
dw TEXT.end-section.TEXT.start
Upvotes: 2