[英]How do you print a newline character in BIOS-level assembly?
我正在嘗試使用NASM Assembler自己編寫一個bootloader。 我正在嘗試打印兩行文本,等待按鍵,如果按下的鍵是'r'則重新啟動,如果按下的鍵是'b'則繼續啟動。 但是,這不是我的問題的主題(我將在稍后實現這些函數,因此目前代碼中的nop
指令)。 相反,我想問一下為什么我的換行符0xA
以這種奇怪的方式打印? 我已經在我的TODO中完成了所有三個項目,但我認為這很重要,因為加載器一定不會看起來很糟糕。
這是我的代碼:
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
在我看來,換行符( 0xa
)完全符合我的預期 - 打印換行符。 但是,您還沒有打印回車符( 0xd
),因此您的下一句話將在屏幕中間開始。 添加回車符,您應該得到您正在尋找的結果。
指令cmp al,0檢查工作字符是否為0.在這種情況下 - 結束例程。 您的字符串必須以0結尾。如示例所示:
... Aryal', 0x0D, 0xA, 0
...booting', 0x0D, 0xA, 0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.