Last active
November 22, 2019 23:47
-
-
Save beiweiqiang/d66937b90ca9e52adc4080461615b4a2 to your computer and use it in GitHub Desktop.
initial program loader 512字节
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; hello-os | |
; TAB=4 | |
org 0x7c00 ; 指明程序装载地址, 因为前面的内存地址已经被占用了 | |
jmp entry | |
db 0x90 | |
db "helloipl" ; 启动区的名称 8字节 | |
dw 512 ; 每个扇区的大小 512 字节 | |
db 1 ; cluster 的大小 (1个扇区) | |
dw 1 ; FAT 的起始位置 (第 1 个扇区开始) | |
db 2 ; FAT 的个数 (2 个) | |
dw 224 ; 根目录的大小 (224项) | |
dw 2880 ; 磁盘大小 (2880 扇区 = 80柱面 * 18扇区 * 2磁头) | |
db 0xf0 ; 磁盘种类 | |
dw 9 ; FAT 长度 (9 扇区) | |
dw 18 ; 一个磁道多少个扇区 (18) | |
dw 2 ; 磁头数量 | |
dd 0 ; 不使用分区 | |
dd 2880 ; 磁盘大小 | |
db 0,0,0x29 | |
dd 0xffffffff | |
db "hello-osiii" ; 磁盘名称 (11字节) | |
db "FAT12 " ; 磁盘格式名称 (8字节) | |
times 18 db 0 ; 空出 18 字节 | |
entry: | |
mov ax, 0 | |
mov ss, ax | |
mov sp, 0x7c00 | |
mov ds, ax | |
mov es, ax | |
mov si, msg | |
putloop: | |
mov ah, 0x0e ; 为了显示字符, 需要将 AX 高位置为 0e | |
mov al, [si] ; 把内存 [si] 的内容搬到 al 里 | |
mov bx, 15 ; 颜色 (但是没有效果) | |
add si, 1 | |
cmp al, 0 ; 如果 al 为 0, 证明内存 [si] 字符串已经结束 | |
je fin ; 如果 al 为 0, 跳转到 fin | |
int 0x10 | |
jmp putloop | |
fin: | |
hlt ; 使 cpu 停止动作 | |
jmp fin ; 无脑跳 fin | |
msg: | |
db "hello, an qi" | |
TIMES 0x1fe-($-$$) DB 0 ; 1fe = 510, 还差 2 字节到 512字节 一个扇区 | |
db 0x55, 0xaa ; 这是第 1 个扇区的最后 2 个字节, 55 aa 决定该扇区的开头是启动程序 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment