简单的引导程序

引导程序是我们开发操作系统的第一步,这里我贴出一个示例,来演示引导程序包含哪些内容。

这是一个简单的引导程序 bootloader, 它只用来显示一串字符, 然后什么都不做。
虽然很精简, 但是你也可以使用 nasm 编译它, 然后写入到 u 盘里在真机上实验。
后续添加代码注释。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
section mbr vstart=0x7c00
start:
;; init regs
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov fs, ax
mov sp, 0x7c00
.clearscreen:
;; clear screen
mov ax, 0x600
mov bx, 700
mov cx, 0
mov dx, 0x184f
int 0x10
.getcursorpos:
;; get position of cursor
mov ah, 3
mov bh, 0
int 0x10
.print:
;; print message at the cursor
mov ax, message
mov bp, ax
mov cx, 8
mov ax, 0x1301
mov bx, 0x2
int 0x10
.halt:
;; endless loop, doing nothing
jmp $
.data:
message db "MBR Demo"
times 510 - ($-$$) db 0
db 0x55, 0xaa