开发者

Order of the [BITS 16] and [ORG 0x0000] directives

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


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜