この記事を見てやりました。

OSを書く:初歩から一歩ずつ | プログラミング | POSTD

環境

Ubuntu Server 64bit

1
2
3
4
5
% cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"

書いたソースコード

; boot.asm
; setup segment register
mov ax, 0x07c0
mov ds, ax
; setup display
mov ah, 0x0 ;setup video mode
mov al, 0x3 ;0x3 = text mode, color, 80x25
int 0x10 ;0x10 = video service
mov si, msg ;target of lodsb
mov ah, 0x0E ;0x0E = tty
print_character_loop:
lodsb
or al, al
jz hang ;jump if zero
int 0x10 ;when ah is 0x0E, then print
jmp print_character_loop
msg:
db 'Hello World!', 13, 10, 0 ;13 = \r, 10 = \n, 0 = NULL
hang:
jmp hang
times 510-($-$$) db 0
; this is a comment
db 0x55
db 0xAA
view raw boot.asm hosted with ❤ by GitHub
boot.bin: boot.asm
nasm -f bin boot.asm -o boot.bin
qemu: boot.bin
qemu-system-x86_64 -curses boot.bin
clean:
rm *.bin
view raw Makefile hosted with ❤ by GitHub
gist.github.com

※qemu実行時の引数について、ssh越しにターミナルで作業していたので、-cursesオプションを付けて起動しています。

作業中の様子

ブートローダーとか書くのは面倒くさそうだなぁ……といったところで、一旦ここまでで終了としました。

一応全部の命令の内容を確認できたので、若干勉強にはなったかなぁと。

参考URL