在汇编BIOS调用中处理换行符/ CR

时间:2009-08-18 10:02:52

标签: assembly bios

我正在学习装配,我正在尝试使用BIOS调用从键盘/打印到键盘进行简单的读取。到目前为止,我有以下内容:

loop:
    xor ah, ah
    int 0x16        ; wait for a charater
    mov ah, 0x0e
    int 0x10        ; write character
    jmp loop

这个工作正常,直到有人按下回车键 - 似乎正在处理CR(\ r)而不是换行符(\ n),因为光标移动到当前行的开头,而不是开始下一行。

有什么想法吗?

1 个答案:

答案 0 :(得分:7)

中断0x16,函数0x00仅为AL中的Enter键(CR,0x0D)返回一个ASCII字符,对中断0x10的调用,函数0x0E将打印此单个ASCII字符。如果您希望代码也吐出LF,则必须测试CR并强制LF输出。

loop:
    xor ah, ah
    int 0x16        ; wait for a charater
    mov ah, 0x0e
    int 0x10        ; write character
    cmp al, 0x0d    ; compare to CR
    jne not_cr      ; jump if not a CR
    mov al, 0x0a    ; load the LF code into al
    int 0x10        ; output the LF
not_cr:
    jmp loop