2017-05-28 75 views
-2

因此,我開始學習彙編,並正在用FASM編寫一個簡單的操作系統。我有一個灰色的頂部欄和一個光標的藍色屏幕,但不能讓文本出現在一行上。在第一行,我希望它說「文件系統」,然後在其他行我想要其他的東西。我把這裏的代碼:如何將文本添加到用匯編編寫的操作系統

mov ax, 9ch 
mov ss, ax 
mov sp, 4096d 
mov ax, 7c0h 
mov ds, ax 
;---------------- 


;this sets blue to background 
mov ah, 09h 
mov cx, 1000h 
mov al, 20h 
mov bl, 17h 
int 10h 
;end of blue 

;start of gray top 
mov ah, 09h 
mov cx, 80d 
mov al, 20h 
mov bl, 87h 
int 10h 
;end of gray 
;top bar 






;end of top bar 
;define mouse 
mov ah, 01h 
mov cx, 07h 
int 10h 

mov bl, 5h 
mov cl, 5h 


_mouser: 
mov ah, 02h 
mov dl, bl 
mov dh, cl 
int 10h 

mov ah, 00h 
int 16h 

cmp al, 77h 
je _up 
cmp al, 73h 
je _down 
cmp al, 61h 
je _left 
cmp al, 64h 
je _right 
cmp al, 20h 
je _click 
jmp _mouser 



_click: 
mov ah, 0eh 
mov al, 0b2h 
int 10h 
jmp _mouser 

_up: 
cmp cl, 0h 
je _mouser 
sub cl, 1h 
jmp _mouser 

_down: 
cmp cl, 24d 
je _mouser 
add cl, 1h 
jmp _mouser 

_left: 
cmp bl, 0h 
je _mouser 
sub bl, 1h 
jmp _mouser 

_right: 
cmp bl, 79d 
je _mouser 
add bl, 1h 
jmp _mouser 



;---------------- 
times 510-($-$$) db 0 
dw 0xAA55 

我曾嘗試

mov ah, eoh 
mov al, 'F' 
int 10h 

問題是,只能使單個字符的字符串。

+0

'mov啊,0eh; mov al,'F'; int 10h'應該更好。 – Jester

+0

是的,我知道這使得一個字符,但我需要一個字符串 –

+0

去花一些時間閱讀維基在http://osdev.org –

回答

3

PC的ROM BIOS提供一組通過中斷10h調用的視頻服務,包括一些將字符打印到字符串的視頻服務。他們的綜合文檔可以在here找到。

看來你已經發現了服務0Eh,它在當前字符位置向屏幕寫入單個字符並且提前字符位置。這將屏幕看作是電傳打字(TTY),並使得在屏幕上獲得輸出變得非常容易。

(至少,它看起來你試圖調用服務0EH。您的代碼是不正確的。你有mov ah, eoh,這是不正確的。o不是一個十六進制值,即使是爲0一個錯字,你又啃相反它應該是mov ah, 0Eh

如果你想打印一個字符串(多個字符),你基本上有兩種選擇:。

  1. 你可以反覆調用像0Eh這樣的服務,將單個字符寫入str每一次。這方面的一個示例實施方式將是:

    mov ah, 0Eh    ; service 0Eh: print char as TTY 
    .PrintNextChar: 
        mov al, BYTE PTR [si] ; get next character in string, pointed to by SI 
        inc si     ; increment pointer 
        test al, al    ; is character == 0 (end-of-string)? 
        je .Done 
        int 10h 
        jmp .PrintNextChar 
    .Done 
    

    此打印從字符串中的字符指向SI直到它到達0(NUL字符),這表示字符串的結束(一個標準的C語言風格NUL-終止的字符串)。

    但是,這種一次打印一字符的方法相對較慢。相反,人們通常更喜歡...

  2. 使用服務1300h或1301h一次打印整個字符串。區別在於服務1301h在打印字符串之後提前光標,而服務1300h不改變光標。否則,他們是一樣的。

    這些服務的參數記錄在上面的鏈接中;這裏重印了方便:

    • AX == 1300H/1301h
    • BL ==視頻屬性(在文本模式中,指定的前景和背景顏色)
    • BH ==視頻頁面(通常爲0)
    • CX串起始位置的
    • DL/DH ==列/行的長度==字符串
    • ES:BP

    的開始==地址顯然,這需要您知道該字符串提前長度,而把它作爲在CX寄存器參數。該字符串由ES:BP指向。

    在你的情況下,打印「文件系統」,你將宣佈一個字符數組中包含該字符串的數據段,然後像做:

    MyString DB "FILE SYSTEM" 
    
    mov ax, ds 
    mov es, ax   ; set ES == DS 
    mov bp, MyString 
    mov cx, 11   ; length of string (number of chars) 
    mov bx, 07h   ; foreground & background color (white on black) 
    xor dx, dx   ; starting position (top-left) 
    mov ax, 1301h  ; service 1301h: print string and update cursor 
    int 10h 
    
+0

非常感謝你爲我工作! –