gpt4 book ai didi

assembly 文本颜色

转载 作者:行者123 更新时间:2023-12-02 15:43:01 25 4
gpt4 key购买 nike

我正在程序集中创建一个 iso 文件,我想为文本添加颜色(在本例中为:红色)。
有谁知道怎么做吗?

[BITS 16]
[ORG 0x7C00]

jmp main

main:
mov si, string ; si=string
call printstr
jmp $

printstr:
lodsb ; al=&si[0]
cmp al,0 ;FLAGS = 0
jnz print
ret

print:
mov ah,0Eh
int 10h
jmp printstr

string db "HELLO WORLD!",13,10,0

times 510 - ($-$$) db 0
dw 0xAA55

最佳答案

作为初步建议,请始终设置引导加载程序所依赖的段寄存器。在这里,因为lodsb[ORG 0x7C00] 一起,您必须设置 DS=0 .
最好还确保方向标志 DF 处于已知状态。一个简单的cld就足够了。

回答你的问题。您使用的 BIOS.Teletype 函数 0Eh 可以产生所需的红色但仅在图形视频模式下。因此,下一个解决方案将起作用:

[BITS 16]
[ORG 7C00h]
jmp main
...
main:
xor ax, ax ; DS=0
mov ds, ax
cld ; DF=0 because our LODSB requires it
mov ax, 0012h ; Select 640x480 16-color graphics video mode
int 10h
mov si, string
mov bl, 4 ; Red
call printstr
jmp $

printstr:
mov bh, 0 ; DisplayPage
print:
lodsb
cmp al, 0
je done
mov ah, 0Eh ; BIOS.Teletype
int 10h
jmp print
done:
ret

string db "HELLO WORLD!",13,10,0

times 510 - ($-$$) db 0
dw 0AA55h

如果您想使用文本视频模式,那么 BIOS.WriteCharacterWithAttribute 函数 09h 是正确的选择。

  • 请注意,因为参数不同BL现在保存一个同时指定 2 种颜色的属性字节(低半字节中的前景和高半字节中的背景),并且额外的参数使用 CX登记。
  • 另一点是,此函数将显示每个 ASCII 代码的彩色字形。因此,除非您采取措施,否则回车符 (13) 和换行符 (10) 将无法正确解释。
  • 然而,最重要的事实是该函数不会使光标前进。幸运的是,有一个巧妙的技巧。只需连续调用函数 09h 和 0Eh 即可...

示例:

[BITS 16]
[ORG 7C00h]
jmp main
...
main:
xor ax, ax ; DS=0
mov ds, ax
cld ; DF=0 because our LODSB requires it
mov ax, 0003h ; Select 80x25 16-color text video mode
int 10h
mov si, string
mov bl, 04h ; RedOnBlack
call printstr
jmp $

printstr:
mov cx, 1 ; RepetitionCount
mov bh, 0 ; DisplayPage
print:
lodsb
cmp al, 0
je done
cmp al, 32
jb skip
mov ah, 09h ; BIOS.WriteCharacterWithAttribute
int 10h
skip:
mov ah, 0Eh ; BIOS.Teletype
int 10h
jmp print
done:
ret

string db "HELLO WORLD!",13,10,0

times 510 - ($-$$) db 0
dw 0AA55h

关于 assembly 文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55009353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com