2019.06.05. 11:08
Hello World OS
A good friend of mine just found an archive of his “operating system”, the “Hello World OS”. It is basically a bootloader, and it gave me such nostalgia that I asked permission to post it:
asm
;; boot "Hello world!" program
;; usage:
;; nasm -fbin hello.asm -o hello.bin
;; UltraISO -bootfile hello.bin -outfile hello.iso
bits 16 ; 16 bit instructions
org 0x7C00 ; BIOS transfers execution here after loading the boot sector
start:
;; zero out ds, because memory references use ds as base
;; ds can only be set via a register so reading from relative addresses would work
mov ax, 0
mov ds, ax
mov si, string ; si points to the string we want to display
loop:
mov al, [si] ; al contains the character we want to display
mov ah, 0xE ; teletype (TTY) mode
mov bl, 0x7 ; text color (doesn't matter in tty mode)
mov bh, 0 ; page number
cmp al, 0
jz loop_end ; end loop if we reached the zero byte
int 0x10 ; BIOS interrupt
inc si
jmp loop
loop_end:
jmp $ ; hog execution forever :D
string db "Hello world!", 13, 10, 0
times 510-($-$$) db 0 ; pad program to 512 bytes with zeroes
dw 0xAA55 ; boot sector closing bytes
Ah, this is amazing. 0x7C00? 0xAA55? Beautiful.