如何在 BIOS 级汇编中打印换行符?
How do you print a newline character in BIOS-level assembly?
我正在尝试使用 NASM 汇编器自行编写引导加载程序。我正在尝试打印两行文本,等待按键,如果按下的键是 '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
) 完全符合我的预期——打印换行符。但是,您还没有打印回车符 return (0xd
),因此您的下一句话从屏幕中间开始。添加回车 return,您应该会得到想要的结果。
指令 cmp al, 0 检查工作字符是否为 0。在这种情况下 - 结束例程。您的字符串必须以 0 结尾。例如:
... Aryal', 0x0D, 0xA, 0
...booting', 0x0D, 0xA, 0
我正在尝试使用 NASM 汇编器自行编写引导加载程序。我正在尝试打印两行文本,等待按键,如果按下的键是 '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
) 完全符合我的预期——打印换行符。但是,您还没有打印回车符 return (0xd
),因此您的下一句话从屏幕中间开始。添加回车 return,您应该会得到想要的结果。
指令 cmp al, 0 检查工作字符是否为 0。在这种情况下 - 结束例程。您的字符串必须以 0 结尾。例如:
... Aryal', 0x0D, 0xA, 0
...booting', 0x0D, 0xA, 0