[BITS 16] 和 [ORG 0x0000] 指令的顺序

发布于 2024-08-25 21:59:35 字数 232 浏览 4 评论 0原文

我正在开始尝试编写内核并享受其中的乐趣。我已经完成了基本的引导加载程序和以下指令:

[BITS 16]
[ORG 0x0000]

但是,在内核教程中,它以:

[ORG 0x0000]
[BITS 16]

我想知道这些指令的给出顺序是否有所不同?我使用的是 NASM 版本 2.06rc2,OpenSUSE 11.2

I am beginning some experimentation in writing a kernel and having fun doing it. I have the basic boot-loader done and the following directives:

[BITS 16]
[ORG 0x0000]

In the kernel tutorial, however, it starts with:

[ORG 0x0000]
[BITS 16]

I was wondering if the order in which these directives are given makes a difference? I am using NASM version 2.06rc2, OpenSUSE 11.2

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

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

发布评论

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

评论(2

萌吟 2024-09-01 21:59:35

最新的 NASM 版本为 2.08,根据 NASM 上的文档判断/www.nasm.us/doc/nasmdoc6.html#section-6.1" rel="nofollow noreferrer">BITS 指令..

该顺序不应产生影响,因为它们告诉 NASM 在某些条件下生成文件,例如使用 16 位并从零开始寻址。由此看来,NASM 似乎足够聪明,知道它会生成什么样的输出。

The latest NASM is at version 2.08, and judging by the documentation on the BITS directive..

The order should not make a difference since they tell NASM to generate a file with certain conditions, such as using 16 bits and addressing start at zero. From it, NASM seems to be smart enough to know what kind of output it will generate.

丿*梦醉红颜 2024-09-01 21:59:35

哪个先出现并不重要,但我通常在程序中遵循以下顺序:(

        cpu 8086
        bits 16
        org 256

因为 bits 16 是 NASM 的 bin 输出格式的默认值,所以我通常不会明确指定它,除非有是文件的一些 bits 32 部分。)

顺便说一句,带括号的形式是这些指令的较低级别的非“用户”形式。 https://www.nasm.us/xdoc/ 2.14.02/html/nasmdoc6.html#section-6.1

BITS 指令具有完全相同的原始形式:[BITS 16]、[BITS 32] 和 [BITS 64]。用户级表单是一个宏,除了调用原始表单外没有其他功能。

It doesn't matter which one comes first, but I generally follow this order in my programs:

        cpu 8086
        bits 16
        org 256

(Because bits 16 is the default for NASM's bin output format I generally do not specify it explicitly, except when there are some bits 32 parts to a file.)

By the way, the forms with brackets are the lower-level, non-"user" forms of these directives. https://www.nasm.us/xdoc/2.14.02/html/nasmdoc6.html#section-6.1

The BITS directive has an exactly equivalent primitive form, [BITS 16], [BITS 32] and [BITS 64]. The user-level form is a macro which has no function other than to call the primitive form.

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