Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

assembly - x86 NASM 'org' directive meaning

I am following this tutorial as a first foray into bootloader/OS development for x86 using NASM:

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

And I'm on Lesson 4, which is making my bootloader print the "Hello, world" string. I'm not understanding the meaning of the org instruction (directive?).

As I understand it, org defines where the program being executed is loaded into memory. 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

org defines where the program in question EXPECTS to be loaded into memory. Not where it actually is loaded -- that is controlled by whoever does the loading -- but where it expects to be loaded.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[6] html - How to create even cell spacing within a

1.4m articles

1.4m replys

5 comments

57.0k users

...