节/段指令有多重要?

发布于 2024-09-09 03:27:16 字数 176 浏览 2 评论 0原文

节/段指令有多重要?我注意到它们通常是可选的。另外,我注意到当您包含或不包含它们时,输出大小会发生变化。

我正在使用 NASM,如果有帮助的话。

How important are section/segment directives? I've noticed that they are usually optional. Also, I've noticed that the output size changes when you do or do not include them.

I'm using NASM, if that helps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷心人i 2024-09-16 03:27:16

它们非常重要,因为如果将字符串保存在代码段中,程序执行速度可能会慢得多,并且字符串会破坏指令缓存中的数据。

如果您创建一个库(.lib 或类似的东西),它也很重要,因为由于上述原因,您不希望数据(字符串)直接位于可执行指令后面。

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.

楠木可依 2024-09-16 03:27:16

对于使用 NASM 的多节 bin 输出格式的任何重要内存布局来说,节都至关重要:https://www.nasm.us/xdoc/2.14.02/html/nasmdoc7.html#section-7.1.3

例如,这些是我正在设置的部分在我的一个程序中: 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 和两个 ASMTABLE 部分都由同一段寻址,并且不会从加载到进程中的位置重新定位。 DATASTACK 也由前一个段寻址,但它是一个 nobits 部分。 CODE 由其自己的段寻址,因此 vstart=0。在初始化期间它也会被重新定位到 DATASTACK 后面的某个位置(具体位置取决于某些情况)。 INIT 也由其自己的段寻址。它首先重新定位自己,并在初始化结束时从进程的内存中丢弃。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文