开发者

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?__

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜