再会。我是汇编语言的新手,我正在尝试在 TASM 中打印一个彩色的“Hello World”。到目前为止,这是我的代码。它只是打印没有颜色的“hello world”。
.model small
.stack 100h
.data
message db 13,10,"Hello World!$"
.code
main proc near
lea dx, message
mov ah, 09h
int 21h
mov ah,4ch
int 21h
main endp
我读过这样的东西
mov ah,9 ;Function 9: Write character and attribute at cursor position
mov al,'H' ;AL = character to display
mov bh,0 ;BH = page number
mov bl,02EH ;BL = attribute (yellow on green)
mov cx,1 ;CX = number of times to write character
int 10H ;Int 10H: Video (show the character)
在论坛中,但我无法将其与我的 hello world 合并。我很困惑为什么要使用那个特定的寄存器等。请帮我。非常感谢你!
编辑
.model small
.stack 100h
.data
hello db 'Hello World!',0
.code
main proc near
mov ax, @data
mov ds, ax
mov ax, 3
int 10h
mov si, 0 ; cl is the counter register, set it to
; zero (the first character in the string)
start: ; Beginning of loop
mov al, hello[si] ; Read the next byte from memory
cmp al, 0 ; Compare the byte to null (the terminator)
je endthis ; If the byte is null, jump out of the loop
mov ah, 09h
mov al, hello[si]
mov bh, 0
mov bl,02EH
mov cx,11
int 10H
add si, 1 ; Move to the next byte in the string
jmp start ; Loop
endthis:
mov ah, 4ch
int 21h
main endp
end main