I am trying to understand how assembling and linking work, so i have a listing file generated using NASM , and I am wandering about meaning of the brackets([]), it's a way to tell that this its a realocateble address that may change in the linking phase?
Edit:I am getting this .lst file using nasm -f obj
1 segment data public
2 00000000 4141414141414141 db 8 dup ('A')
3 segment code public
4 ..start:
5 00000000 B8[ssss] mov ax,data
6 00000003 B8[0300] mov ax,$
7 00000006 B8[0000] mov ax,..start
8 00000009 B80002 mov ax,200h
9 0000000C EBFE jmp $
CodePudding user response:
NASM decorates relocatable values in the listing dump with square brackets [ ] or with parenthesis ( ). This generally signalizes that the value in brackets may differ from the value in linked program, which can be seen in debugger at run-time.
In your 16bits example this difference applies only if your program will be linked with some other module which also defines segment code public
and if this other module goes first, thus elevating assembled offsets in your code
segment. Otherwise offsets at lines 6 and 7 are valid after link-time and those instructions will be encoded as B80300
and B80000
in the final executable (no relocations will apply).
Line 5 is a different beast: it encodes segment address of the first byte of data
segment rather than its offset. Thats why NASM displays the paragraph address with [ssss]
instead of [0000]
and this value will be definitely other than zero - it depends on the address where DOS will load the executable program.
Other assemblers may signalize relocations in listing differently, for instance €ASM uses [ ], ( ) and { } to distinguish absolute, RIP-relative and segment-address relocations.