NASM Specific -- Section vs [SECTION ]
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开发者_如何学Python]
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?__
精彩评论