1) Sure. Try it:
BITS 16
start:
mov ax, 07C0h ; Set up 4K stack space after this bootloader
add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
mov ss, ax
mov sp, 4096
mov ax, 07C0h ; Set data segment to where we're loaded
mov ds, ax
mov si, text_string ; Put string position into SI
call print_string ; Call our string-printing routine
jmp $ ; Jump here - infinite loop!
print_string: ; Routine: output string in SI to screen
mov ah, 0Eh ; int 10h 'print char' function
.repeat:
lodsb ; Get character from string
cmp al, 0
je .done ; If char is zero, end of string
int 10h ; Otherwise, print it
jmp .repeat
.done:
ret
text_string db 'This is my cool new OS!', 0
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC boot signature
Or before...
BITS 16
jmp start
nop
text_string db 'This is my cool new OS!', 0
start:
mov ax, 07C0h ; Set up 4K stack space after this bootloader
add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
mov ss, ax
mov sp, 4096
mov ax, 07C0h ; Set data segment to where we're loaded
mov ds, ax
mov si, text_string ; Put string position into SI
call print_string ; Call our string-printing routine
jmp $ ; Jump here - infinite loop!
print_string: ; Routine: output string in SI to screen
mov ah, 0Eh ; int 10h 'print char' function
.repeat:
lodsb ; Get character from string
cmp al, 0
je .done ; If char is zero, end of string
int 10h ; Otherwise, print it
jmp .repeat
.done:
ret
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC boot signature
In fact, a bootsector is "supposed" to start with a short jmp and a nop, or a near jmp, followed by some disk information. You might even encounter a BIOS that cares. I've never seen it, but I've heard from a guy who was getting "no system disk" from his BIOS. I suggested he try starting with a jmp, and he said it worked. Very rare!
You wouldn't want to put data someplace where it's going to get executed... or after the end of your bootsector.
2) Yes, they're the same. You never "need" a colon after a label. Nasm will warn if there's a label alone on a line without a colon, but it works. This warning can be turned off... and used to be off by default. It was turned on by default because it serves as a sort of spellchecker:
.repeat:
lodbs ; Get character from string
Nasm doesn't know what "lodbs" is, and would silently assemble it as a label-without-a-colon without this warning. Otherwise, either with or without a colon is fine... (you can try this too)
3) Yeah, you've found the Friendly Manual. Sometimes doesn't tell you exactly what you want to know, sometimes tells you too much. Best we can do, at the moment.
You don't ask, but a bootsector is not the easiest thing to write as a first project!
Best,
Frank