boot.asm

来源:互联网 发布:渡口网络 编辑:程序博客网 时间:2024/05/16 19:15

;直接编译成软盘镜像使用  nasm  boot.asm  -o  boot.img

;如果你想在纯dos下运行,将org   07c00h改为 org 0100h
 org 0100h   ; 告诉编译器程序加载到7c00处,不加这一句,打印的字符会是乱码
 mov ax, cs
 mov ds, ax
 mov es, ax
 call DispStr   ; 调用显示字符串例程
 jmp $   ; 无限循环
DispStr:
 mov ax, BootMessage
 mov bp, ax   ; ES:BP = 串地址
 mov cx, MessageLong  ; CX = 串长度
 mov ax, 01301h  ; AH = 13,  AL = 01h
 mov bx, 000ch  ; 页号为0(BH = 0) 黑底红字(BL = 0Ch,高亮)
 mov dl, 0
 int 10h   ; 10h 号中断
 ret
BootMessage:  db "I love you,my motherland!!!"
MessageLong  equ         $-BootMessage
times  510-($-$$) db 0 ; 填充剩下的空间,使生成的二进制代码恰好为512字节
dw  0xaa55    
; 结束标志,修改这里,虚拟机将提示“Boot failed:could not read the boot disk”

;    BootMessage是一个指针,拥有地址
;    MessageLong是一个常数,拥有数值

原创粉丝点击