2017-11-05 10 views
2

私は自分自身でNASMアセンブラを使ってブートローダを書こうとしています。私は2行のテキストを印刷し、キー押下を待ち、押したキーが 'r'であればリブートし、押されたキーが 'b'であれば起動を続けようとしています。しかし、それは私の質問の対象ではありません(私はそれらの機能を後で実装します。したがって、現時点でコードのnop命令)。むしろ、なぜ私の改行文字0xAがこのような変わった形で印刷されるのかを聞きたいのですが?私はTODOの3つの項目すべてを一度に行ったことがありますが、ローダーが悪く見えてはならないので、これが重要だと思います。改行を印刷する -BIOSレベルのアセンブリで改行文字をどのように印刷しますか?

BITS 16  ; tell nasm we're working in 16 bit real mode 

start:   ; entry symbol for the os   

     mov ax, 0x07C0   ; 4 kilobyte stack space set up 
     add ax, 288    ; (4096+512)/16 bytes per paragraph 
     mov ss, ax    
     mov sp, 4096 

     mov ax, 0x07C0   ; set data segment to where we've loaded 
     mov ds, ax 

     mov si, text_string  ; put our string position into SI 
     call write_string  ; call our string-printing function 
     mov si, text_string_tutorial 

     cli      ; jump here for an infinite loop 
     hlt 

     text_string db 'Mao Mao Loader 0.01 written by Safal Aryal', 0xA 
     text_string_tutorial db 'Press r to reboot or b to continue booting', 0x9 


write_string:     ; output string located in si 
    mov ah, 0xE     ; the 'print char' function of int 0x10 
.repeat:     
    lodsb      ; get character from the string 
    cmp al, 0     ; check if it is zero 
    je .done     ; if it is, jump to .done and finish the function 
    int 10h      ; call interrupt 10h  
    jmp .repeat     ; repeat for every char in the string 
.done:     
    ret 

read_input: 
    mov ah, 0x00 
    int 16h 
    cmp al, 'r' 
    nop 
    cmp al, 'b' 
    nop 

    times 510-($-$$) db 0  ; pad boot sector with zeroes 
    dw 0xAA55     ; standard bootsig 

;TODO: read key pressed, change background colour and start writing kernel 

答えて

5

それは改行(0xa)私が期待するかを正確にやっているように私には見えます:

the output

は、ここに私のコードです。しかし、キャリッジリターン(0xd)も印刷しなかったので、次のセンテンスは画面の中央で開始されます。キャリッジリターンを追加すると、探している結果が得られるはずです。

1

命令cmp al、0 working charが0であるかどうかをチェックします。このケースでは、ルーチンを終了します。文字列は0で終わらなければなりません。例:

... Aryal', 0x0D, 0xA, 0 
...booting', 0x0D, 0xA, 0 
関連する問題