简体   繁体   English

x86 NASM'org'指令含义

[英]x86 NASM 'org' directive meaning

I am following this tutorial as a first foray into bootloader/OS development for x86 using NASM: 我正在关注本教程,作为使用NASM进行x86的bootloader / OS开发的第一次尝试:

http://joelgompert.com/OS/TableOfContents.htm http://joelgompert.com/OS/TableOfContents.htm

And I'm on Lesson 4, which is making my bootloader print the "Hello, world" string. 我正在第4课,这使我的引导程序打印出“Hello,world”字符串。 I'm not understanding the meaning of the org instruction (directive?). 我不理解org指令(指令?)的含义。

As I understand it, org defines where the program being executed is loaded into memory. 据我了解, org定义了正在执行的程序被加载到内存中的位置。 This is needed when using any sort of labels or relative addresses in the program. 在程序中使用任何类型的标签或相对地址时都需要这样做。

Suppose I have a string defined with a label like this in my program: 假设我的程序中有一个用这样的标签定义的字符串:

szHello db 'Hello, world!', 0

And I then later try to reference that label like this (only relevant snippets): 然后我尝试像这样引用该标签(仅相关的片段):

org 0x7c00
xor ax, ax
mov ds, 0
...
mov si, szHello
lodsb
...
int 0x10 ; Print first character of szHello

My question is, why is that not equivalent to this? 我的问题是,为什么这不等于这个? :

org 0
mov ds, 0x7c00
...
mov si, szHello
lodsb
...
int 0x10

When I run the first example, my string appears correctly. 当我运行第一个示例时,我的字符串正确显示。 The second example does not work. 第二个例子不起作用。

Pointers to relevant documentation would also be greatly appreciated, if the issue is a conceptual problem on my part. 如果问题是我的概念问题,也会非常感谢相关文档的指针。

org defines where the program in question EXPECTS to be loaded into memory. org定义有问题的程序EXPECTS要加载到内存中的位置。 Not where it actually is loaded -- that is controlled by whoever does the loading -- but where it expects to be loaded. 不是它实际加载的地方 - 由负载的任何人控制 - 但它预期加载的位置。

0000:7C00 is not equivalent to 7C00:0000. 0000:7C00不等于7C00:0000。 The segment part is counted in paragraphs, not bytes. 段部分以段落计算,而不是字节。 Try this instead: 试试这个:

mov ax, 0x7c0 
mov ds, ax

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM