elias wrote:
so even if my kernel is loaded at 0x8000, my org shoud still be 0x0000? perhaps i dont understand the org staements use. ive read teh nasm doc, btu coudl someone explain it?
The ORG statement sets the code entry point, that is, the location relative to the segment base where the code should be assembled to load at. All labels are calculated from that location. Thus, if your segment base is 0x0000, then ORG 8000 will assemble your code to begin at 0000:8000. For example, in the following code:
Code: Select all
[org 8000]
start:
mov cx, 0
gatherloop:
in al, 0x3E
jz end
mov [es:si], al
inc si
jmp gatherloop
end:
jmp $
the labels would be calculated from 0x8000, and thus, start == 0x8000, gatherloop = 0x8003, and end == 0x800F.
However, using the ORG statement does
not cause the code to automatically start running at 0000:8000 (absolute address 0x08000). In order to ensure that it begins at the correct place, you would have to ensure that control is correctly transferred to it by the first stage boot loader.
Now, there is no reason why you couldn't do this, but there are a few good ones why you probably shouldn't. First off, you've ignored half of the space in the segment you are using, giving you only 32Kbytes of working space - while this is probably plenty at this point, it will quickly become a limiting factor as you develop your kernel. Second, since the ORG statement in real mode is relative to the code segment base (held in the CS register) rather than an absolute value, if youd don't set your CS to what you want it to be first, you could be loading to 4A09:8000 (absolute address 0x52090) or 9000:8000 (absolute address 0x98000) just as easily as to 0x08000. If you want to load to a particular absolute address, it is better to use the segment base to set the entry point, and use an offset (and an ORG) of zero, I think.
Again, I don't know if this is relevant to your code or not. If you could show the code, it would make a big difference in how we can help you.