Reputation: 3
I'm working on an operating system that is written in x86 Intel Assembly, and I noticed some guides, like the OS Dev wiki, has mov ax, 07c0
at the very start in their examples. Then, from my research on writing an operating system, I've found, for example, YouTube videos on this subject that put org 0x7C00
at the beginning of the boot loader file.
My question is: Is there any difference between the two? And if their is, which is the better choice, and what exactly are the differences?
Upvotes: 0
Views: 664
Reputation: 29042
Is there any difference between the[se] two?
To understand the difference between those two, you have to understand the segment:offset
model of 8086 assembly:
In REAL mode a segment value denotes a value 16(dec)=10(hex) times the value of an offset value.
So a value of segment 0000
and offset 0x7c00
denotes the same position in memory as segment 07C0
and offset 0000
= 07C0h * 10h = 7C00h. See here at OSDev:RealMode for an extended explanation.
So overall 0000:7C00
is the same as 07C0:0000
.
With the ORG
directive you do set the beginning of a (memory) section.
Is there any difference between the two?
Yes. The difference between these two is the setup of the segment registers and the address registers. If you set the segment registers in a specific way, you'd have to set the address/offset registers in a related way.
And if their is, which is the better choice, and what exactly are the differences?
There is no "better" choice. It's just a design decision which is merely relevant until you enter Protected Mode and set up your GDT.
Upvotes: 2