我正在尝试打印带有白色前景和蓝色背景的字符串:
[BITS 16] ;16 bit code
[ORG 0x7C00] ;Origin location
SECTION .DATA ;Data section
output: db 'Hello World', 10, 0 ;Output string (10 = \n, 0 = \0)
;Entry point
main:
mov ax, 0x0000 ;Initialize the ds register
mov ds, ax ;ds isn't a general purpose register => value has to be copied
mov si, output ;Load the string into the si register
call printString ;Call the printString function
jmp $ ;Endless loop
;Prints output
printString:
mov ah, 0x0E ;Function 0x0E = Display character
mov bh, 0x00 ;Set the page number to zero
mov bl, 0x1F ;Set the text attribute (0x1F = Blue bg, White fg)
jmp printChar ;Jmp to printChar (just for code eroticism)
;Prints every char from output until 0
printChar: ;Jmp point to loop through the string
lodsb ;Load the byte at si into al
or al, al ;Sets the zero flag if al = 0
jz return ;Return if the end of the string is reached
int 0x10 ;Call the bios video service
jmp printChar ;Continue to print the string
;Returns to main
return: ;Jmp point to return
ret ;Return to main
times 510-($-$$) db 0 ;Fill the rest of the floppy with zeros
dw 0xAA55 ;Boot loader signature
打印“Hello World”并跳转到下一行,但它总是灰色为黑色。不应mov bl, 0x1F
int 0x10
将其着色吗?
修改
如果有人遇到同样的问题:我添加了此功能来更改颜色并删除了文本属性行:
setColors:
mov ah, 0x06 ;Function 0x06 = Scroll up function
xor cx, cx ;From upper left corner
mov dx, 0x184F ;To lower right corner
mov bh, 0x1F ;Set colors (white on blue)
int 10H ;Call the bios video interrupt
ret ;Return
答案 0 :(得分:2)