Why org 07c00h?

Source: Internet
Author: User

Why org 07c00h?

Many people read the book "write your own operating system" or the second version of this book, and then raise questions about this line.

The author explains this question in the book:

Tell the compiler about the futureProgramTo be loaded to 07c00 for execution.

 

To be honest, this book "write your own operating system" is indeed well written. I do not admire the author's level, but the perseverance of the author.
With such a dry knowledge system, you can practice and write books step by step (it is more difficult than writing a blog at will), and
The author tries his best to make it clear to readers. However, the author does not understand these words at all. Of course, we believe that the author
I must understand it, but this statement "shows" I don't understand.

We know that the compiler calculates the relative address for the instruction address during assembly, while for the Boot Sector, everything is from nothing
The Execution Code Compiled with the relative address is converted into an absolute address.

Generally, the "actual starting Boot Sector" will be fixed to the 07c00. The idea is to say a real Boot Sector.
There is a primary Boot Sector on the hard disk, which is then used to control and other boot sectors, such as grub for Windows and Linux.
The Main Boot Sector will be loaded at 0600h. When other bootable sector is selected, the real bootable sector will be loaded to 07c00h.
So in general, the real bootable slice is loaded at 07c00h.

This is because the address of the compiler during compilation is calculated starting from the first line using limit H. Suppose we define a STR: DW "ZXY"
Its relative address is 0100 H. If mov ax STR is used, 0100h is passed to ax, which is fixed in the compiled Execution Code.
The pilot sector is executed with an absolute address, and the command is executed from 07c00h. Therefore, 0100h access is definitely incorrect.
The absolute address of is 07c00h + 0100 H, so if you do not write org 07c00h, write mov ax STR as mov ax STR + 07c00h
The address transfer operation is the same purpose. For the author's program, you can remove org 07c00h from the first line. Set "mov ax, bootmessage"
Change to "mov ax, bootmessage + 07c00h", and the effect is the same.

However, if there are a large number of address transfer operations, it will require + 07c00h in every place, which is a headache.

Therefore, adding org 07c00h to the first line only enables the compiler to compile the first instruction from the relative address org 07c00h.
After the relative address is compiled and loaded, it exactly matches the absolute address.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.