Last active
November 22, 2019 14:43
-
-
Save beiweiqiang/f172c0367628c88d72d1a52b8347773c to your computer and use it in GitHub Desktop.
os asm
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 | |
db 0xeb, 0x4e, 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 字节 | |
db 0xb8, 0x00, 0x00, 0x8e, 0xd0, 0xbc, 0x00, 0x7c | |
db 0x8e, 0xd8, 0x8e, 0xc0, 0xbe, 0x74, 0x7c, 0x8a | |
db 0x04, 0x83, 0xc6, 0x01, 0x3c, 0x00, 0x74, 0x09 | |
db 0xb4, 0x0e, 0xbb, 0x0f, 0x00, 0xcd, 0x10, 0xeb | |
db 0xee, 0xf4, 0xeb, 0xfd | |
db 0x0a, 0x0a ; 2 个换行 | |
db "hello an qi" | |
db 0x0a | |
db 0 | |
TIMES 0x1fe-($-$$) DB 0 ; 1fe = 510, 还差 2 字节到 512字节 一个扇区 | |
db 0x55, 0xaa ; 这是第 1 个扇区的最后 2 个字节, 55 aa 决定该扇区的开头是启动程序 | |
db 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 | |
times 4600 db 0 | |
db 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 | |
times 1469432 db 0 | |
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 al, [si] ; 把内存 [si] 的内容搬到 al 里 | |
add si, 1 | |
cmp al, 0 ; 如果 al 为 0, 证明内存 [si] 字符串已经结束 | |
je fin ; 如果 al 为 0, 跳转到 fin | |
mov ah, 0x0e | |
; mov bx, 15 | |
int 0x10 | |
jmp putloop | |
fin: | |
hlt | |
jmp fin ; 无脑跳 fin | |
msg: | |
; db 0x0a, 0x0a | |
db "hello, an qi" | |
; db 0x0a | |
; db 0 | |
TIMES 0x1fe-($-$$) DB 0 ; 1fe = 510, 还差 2 字节到 512字节 一个扇区 | |
db 0x55, 0xaa ; 这是第 1 个扇区的最后 2 个字节, 55 aa 决定该扇区的开头是启动程序 | |
; db 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 | |
; times 4600 db 0 | |
; db 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00 | |
; times 1469432 db 0 | |
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
#! /bin/bash | |
nasm os.asm -o os.img | |
qemu-system-i386 os.img |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment