I cannot seem to find anything clear in NASM's documentation regarding the difference between using Section or [SECTION ] (with the brackets) in your code. I am aware these are macros, but I see them used almost interchangeably. Is this the case? In other words is
[SECTION .text]
Equivalent to
Section .text
?
Do brackets maybe imply some arcane side effect?
Thanks
[SECTION .xyz]
is the primitive form of the section directive which simply sets the current output section, SECTION .xyz
differs slightly because it works like a macro:
SECTION .text
expands to the two lines
%define __SECT__ [SECTION .text]
[SECTION .text]
which can be used in conjunction with a macro to temporarily switch the output section, and switch it back to its original value. Example from the NASM manual:
%macro writefile 2+
[section .data]
%%str: db %2
%%endstr:
__SECT__
mov dx,%%str
mov cx,%%endstr-%%str
mov bx,%1
mov ah,0x40
int 0x21
%endmacro
When you use this macro, the output section is set to .data
temporarily by the primitive form of SECTION
, and set back to its original value with __?SECT?__
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With