NASM Specification - Section Against [SECTION]

I cannot find anything in the NASM documentation regarding the difference between using a section or [SECTION] (using brackets) in your code. I know that these are macros, but I see that they are used almost interchangeably. This is true? In other words,

[SECTION .text] 

Equivalent

 Section .text 

?

Perhaps the brackets may have some sort of secret side effect?

thanks

+4
source share
1 answer

[SECTION.xyz] is a primitive form of section directive that simply sets the current output section, "SECTION.xyz" is slightly different because it works like a macro:

 SECTION .text 

expands to two lines

 %define __SECT__ [SECTION .text] [SECTION .text] 

which can be used in conjunction with a macro to temporarily switch the output section and return 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 temporarily set to .data in the primitive form SECTION and returns the original value with __ SECT __

+2
source

All Articles