Writing a Simple Operating System — from Scratch

(Jeff_L) #1

CHAPTER 3. BOOT SECTOR PROGRAMMING (IN 16-BIT REAL


MODE) 12


triggering a specific interrupt. The specific routine we want is the BIOS scrolling tele-
type routine, which will print a single character on the screen and advance the cursor,
ready for the next character. There is a whole list of BIOS routines published that show
you which interrupt to use and how to set the registers prior to the interrupt. Here, we
need interrupt0x10and to setahto0x0e(to indicate tele-type mode) andalto the
ASCII code of the character we wish to print.


;
; A simple boot sector that prints a message to the screen using a BIOS routine.
;

mov ah, 0x0e ; int 10/ah = 0eh -> scrolling teletype BIOS routine

mov al, ’H’
int 0x
mov al, ’e’
int 0x
mov al, ’l’
int 0x
mov al, ’l’
int 0x
mov al, ’o’
int 0x

jmp $ ; Jump to the current address (i.e. forever).

;
; Padding and magic BIOS number.
;

times 510-($-$$) db 0 ; Pad the boot sector out with zeros

dw 0xaa55 ; Last two bytes form the magic number ,
; so BIOS knows we are a boot sector.

Figure 3.2:


Figure 3.2 shows the whole boot sector program. Notice how, in this case, we only
needed to setahonce, then just changedalfor different characters.


b4 0e b0 48 cd 10 b0 65 cd 10 b0 6c cd 10 b0 6c
cd 10 b0 6f cd 10 e9 fd ff 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*
00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa

Figure 3.3:

Free download pdf