why org 07c00h?
A lot of people are asking questions about this line after they read the book, "write their own operating system" or their second edition.
This question is explained in the book by the author:
Tell the compiler that in the future our program will be loaded into the 07c00 for execution.
To tell the truth, "write your own operating system" this book is really good, I do not admire the author's level, but the author's perseverance, can put
So withered 橾 knowledge systematically step-by-step hands-on and written book (difficult than we casually write blog is difficult to dope it), and
The author tries his best to make it clear to the reader. But these words, the author does not understand at all. Of course, we believe in the author.
I certainly understand, but such a statement "shows" do not understand.
We know that the compiler itself calculates the relative address for the address of the instruction at the time of assembly. And for the boot sector, it's all just from nothing.
Phase is performed at an absolute address. Then the execution code compiled with the relative address is converted to an absolute address.
In general, the "boot sector that actually starts executing" is fixed to the 07c00, and the idea is to say a real boot sector.
For a hard disk, there will be a primary boot sector, which then controls and other boot sectors, such as grub control Windows,linux, and so on.
The primary boot sector is then loaded at 0600h, and the real bootable sector is loaded into the 07c00h when other bootable sectors are selected.
So in general, the real bootable sector is loaded into the 07c00h section.
Because the compiler's address at compile time is relative to the beginning of the first line starting with 0000h. If we define a STR:DW "Zxy"
Its relative address is 0100h, and if we have MOV ax STR then we are going to pass 0100h to AX, which is fixed in the compiled execution code.
And the boot sector is executed using an absolute address, and the instruction starts at the 07c00h, so access to 0100h is definitely an error. Real
The absolute address is 07c00h+0100h, so if you don't write org 07c00h, turn mov ax str into MOV ax str+07c00h for
The transfer operation is the same. For the author of the program can remove the first row of org 07c00h. "mov ax,bootmessage"
Change to "mov ax,bootmessage+07c00h", the effect is the same.
But if there is a lot of access to the operation, it must be in every place to +07c00h, it is a very headache.
So in the first row plus org 07c00h just let the compiler start compiling the first instruction from the relative address org 07c00h, the following
The relative address is compiled and loaded to match exactly the absolute address.