ORG and Segment descriptors
Posted: Tue Sep 07, 2004 4:50 pm
I've written a simple bootloader that reads another small program off the second sector of my floppy. I use the ORG directive in the bootloader, and set some segment registers equal to CS in both. At their current state they both work. What I want to know is why I don't need the ORG directive in prog.s. Also, do I really need to set the segment registers to CS? If so, how come?
loader.s
prog.s
loader.s
Code: Select all
BITS 16
ORG 07C00h
jmp 00000h:main
main:
mov ax, cs
mov ds, ax
mov es, ax
reset:
xor ax, ax
xor dl, dl
int 13h
jc reset
loadSector:
mov ax, 1000h
mov es, ax
mov bx, 0
mov ah, 2
mov al, 1
mov ch, 0
mov cl, 2
mov dh, 0
mov dl, 0
int 13h
jc loadSector
jmp 1000h:0000
times 512 - ($ - $$) - 2 db 0
dw 0AA55h
Code: Select all
mov ax, cs
mov ds, ax
mov si, helloWorld
jmp printString
jmp $
printString:
mov ah, 00Eh
mov bh, 000h
mov bl, 007h
.nextChar:
lodsb
cmp al, 0
je .doneString
int 10h
jmp .nextChar
.doneString
ret
helloWorld db 'Hello, World', 13, 10, 0