操作系統引導區代碼

最近在看寫操作系統相關的書,這裏給出一段書上引導區的代碼,因爲是彙編,而且是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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章