《自己动手写操作系统》学习笔记
之 hello world
计算机加电启动后,从引导扇区把代码加载到内存的0x07c00位置,然后运行机器码。
这里使用nasm汇编将显示hello world 字符串的代码编译成二进制代码,然后使用dd制作虚拟软盘,通过VirualBox虚拟机加载软盘。
首先新建一个虚拟机,操作系统选择other,其他选项只要最低配置即可。
在Storage 中设置软驱。
选择之后要介绍的虚拟软驱文件。
编辑asm文件如下
org 0x7c00 ; 将 ds es 设置成和cs 相同 mov ax,cs mov ds,ax mov es,ax call DispStr jmp $ DispStr: mov ax,BootMsg mov bp,ax ; cx 字符个数 mov cx,16 ; 显示参数 mov ax,0x1301 mov bx,0x000c mov dl,0 ; 调用中断 int 10h ret BootMsg db "hello, os world!" ; 余下到部分填0 times 510-($-$) db 0 ; 引导区以0x55aa结束 dw 0xaa55
编写Makefile文件
all: # 编译asm文件 nasm -o boot.bin boot.asm # 构建虚拟软盘 dd if=boot.bin of=disk512.img bs=512 count=1
然后在虚拟机中选择软盘文件,运行虚拟机。
屏幕上显示helloworld成功