开发者

How important are section/segment directives?

开发者 https://www.devze.com 2023-01-06 20:09 出处:网络
How important are section/segment directives? I\'ve noticed that they are usually optional. A开发者_如何学Pythonlso, I\'ve noticed that the output size changes when you do or do not include them.

How important are section/segment directives? I've noticed that they are usually optional. A开发者_如何学Pythonlso, I've noticed that the output size changes when you do or do not include them.

I'm using NASM, if that helps.


They are very important because if you save your strings in the Code segment the program could execute much slower and the Strings blow up the data in the Instruction cache.

If you create a Library(.lib or something like that) it is also important because you don't wan't data (strings) to lay directly behind your executable instructions because of the reasons above.


Sections are crucial to any non-trivial memory layout using NASM's multisection bin output format: https://www.nasm.us/xdoc/2.14.02/html/nasmdoc7.html#section-7.1.3

For example, these are the sections I'm setting up in one of my programs: https://hg.ulukai.org/ecm/ldebug/file/126b4d793c94/source/debug.asm#l109

        cpu 8086
        org 100h
        addsection lDEBUG_DATA_ENTRY, align=16 start=100h
data_entry_start:
        addsection ASMTABLE1, align=16 follows=lDEBUG_DATA_ENTRY
        addsection ASMTABLE2, align=16 follows=ASMTABLE1
        addsection lDEBUG_CODE, align=16 follows=ASMTABLE2 vstart=0
code_start:
        addsection DATASTACK, align=16 follows=ASMTABLE2 nobits
        addsection INIT, align=16 follows=lDEBUG_CODE vstart=0

DATA_ENTRY and both ASMTABLE sections are all addressed by the same segment and are not relocated from where they are loaded into the process. DATASTACK is also addressed by the prior segment, but is a nobits section. CODE is addressed by its own segment, thus vstart=0. It is also relocated to somewhere behind DATASTACK during initialisation (the exact position depends on some circumstances). INIT is also addressed by its own segment. It relocates itself first, and is discarded from the process's memory at the end of initialisation.

0

精彩评论

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