为什么使用0EH 10H中断时不文本颜色的? [英] Why isn't the text colored when using the 0Eh 10h interrupt?

查看:222
本文介绍了为什么使用0EH 10H中断时不文本颜色的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是AH的10H中断作为0EH输出的Hello World!该文本是ouputted,但它不是彩色的。我跑它的qemu-系统-x86_64的,用NASM组装和我的code是如下:

 位16 开始:
    MOV AX,07C0h;设置4K堆栈空间这个引导程序后,
    加斧,288; (4096 + 512)每个段落/ 16字节
    MOV SS,AX
    MOV SP,4096    MOV AX,07C0h;将数据段的地方,我们是装
    MOV DS,AX
    MOV SI,text_string的;把字符串的位置为SI
    调用print_string;请拨打我们的字符串打印程序    JMP $;跳转这里 - 无限循环!
    text_string的分贝的'Hello World!,0
 print_string:;常规:在SI输出字符串到屏幕
    MOV啊,0EH; INT 10H打印字符'函数
    MOV BH,为0x00
    MOV BL,0×03 。重复:
    LODSB;从字符串获取字符
    CMP人,0
    JE .done;如果char是零,字符串的结尾
    INT 10H;否则,打印
    JMP .repeat .done:
    RET
    次510 - ($ - $$)分贝0;垫启动扇区0的剩余
    DW 0xAA55将;标准的PC引导签名


解决方案

我是能够通过使用09为10H中断与彩色打印,而不是0E。你这样做,但是,要改变每一个字符后,光标位置使用此方法。这里是工作code。

 位16开始:
    MOV AX,07C0h;设置4K堆栈空间这个引导程序后,
    加斧,288; (4096 + 512)每个段落/ 16字节
    MOV SS,AX
    MOV SP,4096    MOV AX,07C0h;将数据段的地方,我们是装
    MOV DS,AX
    MOV SI,text_string的;把字符串的位置为SI
    调用print_string;请拨打我们的字符串打印程序    JMP $;跳转这里 - 无限循环!
    text_string的分贝的'Hello World!,0
print_string:;常规:在SI输出字符串到屏幕
 。重复:
    MOV啊,09H; INT 10H打印字符'函数
    MOV BH,为0x00
    MOV BL,0×03
    MOV CX,01H
    LODSB;从字符串获取字符
    CMP人,0
    JE .done;如果char是零,字符串的结尾
    INT 10H;否则,打印
    MOV BH,00H
    MOV啊,03H
    INT 10H
    MOV啊,02H
    MOV BH,00H
    INC。DL
    INT 10H
    JMP .repeat .done:
    RET
    次510 - ($ - $$)分贝0;垫启动扇区0的剩余
    DW 0xAA55将;标准的PC引导签名

I'm using the 10h interrupt with AH as 0Eh to output "Hello World!" The text is ouputted but its not colored. I'm running it on qemu-system-x86_64, assembling with NASM, and my code is as follows:

 BITS 16

 start:
    mov ax, 07C0h           ; Set up 4K stack space after this bootloader
    add ax, 288             ; (4096 + 512) / 16 bytes per paragraph
    mov ss, ax
    mov sp, 4096

    mov ax, 07C0h           ; Set data segment to where we're loaded
    mov ds, ax


    mov si, text_string     ; Put string position into SI
    call print_string       ; Call our string-printing routine

    jmp $                   ; Jump here - infinite loop!


    text_string db 'Hello World!', 0


 print_string:                   ; Routine: output string in SI to screen
    mov ah, 0Eh             ; int 10h 'print char' function
    mov bh, 0x00
    mov bl, 0x03

 .repeat:
    lodsb                   ; Get character from string
    cmp al, 0
    je .done                ; If char is zero, end of string
    int 10h                 ; Otherwise, print it
    jmp .repeat

 .done:
    ret


    times 510-($-$$) db 0   ; Pad remainder of boot sector with 0s
    dw 0xAA55               ; The standard PC boot signature

解决方案

I was able to print with color by using the 09 for the 10h interrupt, instead of 0E. You do, however, have to change the cursor position after each character to use this method. Here is the working code.

     BITS 16

start:
    mov ax, 07C0h           ; Set up 4K stack space after this bootloader
    add ax, 288             ; (4096 + 512) / 16 bytes per paragraph
    mov ss, ax
    mov sp, 4096

    mov ax, 07C0h           ; Set data segment to where we're loaded
    mov ds, ax


    mov si, text_string     ; Put string position into SI
    call print_string       ; Call our string-printing routine

    jmp $                   ; Jump here - infinite loop!


    text_string db 'Hello World!', 0


print_string:                   ; Routine: output string in SI to screen


 .repeat:
    mov ah, 09h             ; int 10h 'print char' function
    mov bh, 0x00
    mov bl, 0x03
    mov cx, 01h
    lodsb                   ; Get character from string
    cmp al, 0
    je .done                ; If char is zero, end of string
    int 10h                 ; Otherwise, print it
    mov bh, 00h
    mov ah, 03h
    int 10h
    mov ah, 02h
    mov bh, 00h
    inc dl
    int 10h
    jmp .repeat

 .done:
    ret


    times 510-($-$$) db 0   ; Pad remainder of boot sector with 0s
    dw 0xAA55               ; The standard PC boot signature

这篇关于为什么使用0EH 10H中断时不文本颜色的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆