Disk Operating System/Hello, World!
Objective[edit | edit source]
|
Hello, World![edit | edit source]Going Deeper[edit | edit source]So far we have a working bootloader that just hangs the computer. Obviously, you'd anticipate it to do more than that and it can. By using a BIOS interrupt, we can display a single ASCII character on the screen. Specifically, we'll be using Int 10h, which is the BIOS interrupt that interacts with the screen. There is a list of int 10h functions on Wikipedia if you need further reference. The code below prints a ASCII character on the screen and hang the computer. org 0x7C00
; Prints a uppercase A.
mov ah, 0x0E
mov al, 'A'
mov bh, 0x00
int 10h
; This hangs the computer.
cli
hlt
; Fills our bootloader with zero padding.
times 510-($-$$) db 0
; This is our boot sector signature, without it,
; the BIOS will not load our bootloader into memory.
dw 0xAA55
In the above code, Now that we have a way to print characters onto the screen we can make a string printing function. We'll have to setup some things up and change things around for this to work, though. org 0x7C00
; Prints a string
mov si, string
call print_string
; Set direction flag.
cld
; This hangs the computer.
cli
hlt
print_string:
; In SI = String.
; Out = Nothing.
; Setup int 10h parameters.
mov ah, 0x0E
mov bh, 0x00
.loop:
; Load a byte from SI into AL
; and then increase SI.
lodsb
; If AL contains a null-terminating
; character, then stop printing.
cmp al, 0x00
je .done
int 10h
jmp .loop
.done:
; Return control to the caller.
ret
string: db "Hello, world!", 0
; Fills our bootloader with zero padding.
times 510-($-$$) db 0
; This is our boot sector signature, without it,
; the BIOS will not load our bootloader into memory.
dw 0xAA55
Whoa, that's a lot of new code! Let's break it down.
|
Assignments[edit | edit source]
|
|