catch 发表于 2013-4-10 19:49:33

Boot Sector 分析

本帖最后由 catch 于 2013-4-10 19:53 编辑

Boot Sector 的 NASM 程序


org0x7c00
movax, cs
moves, ax

call DisplayString
cli
hlt


DisplayString:
    movax, BootMessage
    movbp, ax         ; es:bp = Offset of String(BootMessage)
    movcx, 16         ; cs = String Length(BootMessage)
    movax, 1301h      ; ah = 13h, al = 01h(Write mode)
    movbx, 000ch      ; Page Number = 0(bh = 0), 黑底红字(bl = 0Ch,高亮)
    movdl, 0
    int10h
    ret

BootMessage:            db      "Hello, OS World!"

times   510 - ($ -$$)   db      0

dw      0xaa55

控制BIOS,将代码起始位置放置于: 0x7c00 处。(CS = 0x0,IP = 0x7c00, 结合起来,代码所在的内存地址为:0x0:0x7c00 = 0x7c00)


调用 BIOS 中断 int 10h, 显示字符串到屏幕

有的程序用 jmp $ 代替此处。但 jmp $ 会使 CPU 不停地进行忙碌死循环。
cli 指令,表示 Clear Interrupts,关闭所有的硬件中断。
hlt 指令,表示停止 CPU 运行。



页: [1]
查看完整版本: Boot Sector 分析