pts
pts

Reputation: 87371

Getting section size with nasm -f bin

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:

Upvotes: 1

Views: 800

Answers (1)

pts
pts

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

Related Questions