最近在看写操作系统相关的书,这里给出一段书上引导区的代码,因为是汇编,而且是NASM汇编,所以看了蛮久的。

先给出NASM字符串显示的INT 10中断需要的准备工作:

INT 10 - VIDEO - WRITE STRING (AT and later,EGA)
AH = 13h
AL = write mode
   bit 0: update cursor after writing
   bit 1: string contains alternating characters and attributes
        当al=1的时候,需要处理的是有属性的字符.楼主给的不是ax=01301h吗?al=01
   bits 2-7: reserved (0)
BH = page number
        bh是页号,直接写裸机程序就是0
BL = attribute if string contains only characters
        有人问到的,bl 就决定了字符的样式,颜色等。bl=0ch是黑底红字,高亮,可以换其它的
看看。
CX = number of characters in string
        字符数,楼主好像要修改一下,因为 Funcking your monther!是22个字符。
DH,DL = row,column at which to start writing
        打印时的位置,行列.
ES:BP -> string to write
        打印的字符。
Return: nothing

 

 

所以一段线在显存中显示字符串的函数应该这样编写:

DisPlayStr:
      mov ax, BootMessage
      mov bp,ax
      mov cx,16
      mov ax,01301h
      mov bx,000ch
      mov dx,0102h
      int 10h
      ret

 

 

一个简单的引导区代码编写如下,其他部分的解释可以操作《自己动手写操作系统》这本书

org 07c00h
mov ax,cs
mov ds,ax
mov es,ax
call DisPlayStr
jmp $

DisPlayStr:
      mov ax, BootMessage
      mov bp,ax
      mov cx,16
      mov ax,01301h
      mov bx,000ch
      mov dx,0102h
      int 10h
      ret

BootMessage:   db    "Hello OS World!"
times 510-($-$$) db 0
dw 0xaa55