美好的一天。我是汇编语言的新手,我正试图在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世界合并。我很困惑为什么要使用那个特定的寄存器之类的东西。请帮我。非常感谢你!
修改
.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
答案 0 :(得分:0)
如果您正在使用DOS程序集进行编程,那么您应该熟悉一些常用的中断,例如int 10h
和int 21h
。对于每个中断子功能,需要通过一个或多个寄存器传递给它的相应参数集。
您粘贴的示例代码中使用的中断是“在CURSOR位置处写字符和属性”,您可以找到其描述here。
为了显示具有颜色属性的字符串,您必须在循环中迭代字符串,并使用适当的参数为每个字符调用中断。
答案 1 :(得分:0)
汇编语言与任何编程语言一样,是任意设计决策的结果。有时可能有一个原因,为什么一个特定的寄存器被用作中断调用输入寄存器(优化),但很多时候没有,你只需要把接口(这里int 10h
或int 21h
)作为理所当然的。
与您的问题相关的多个感叹号!!!!!!!!!!!
(我假设有11个感叹号),您的int 10
中断调用中的参数不正确:
mov cx,11
根据Ralf Brown's Interrupt List,mov ah,9
,int 10h
的参数如下:
INT 10 - VIDEO - WRITE CHARACTER AND ATTRIBUTE AT CURSOR POSITION
AH = 09h
AL = character to display
BH = page number (00h to number of pages - 1) (see #00010)
background color in 256-color graphics modes (ET4000)
BL = attribute (text mode) or color (graphics mode)
if bit 7 set in <256-color graphics mode, character is XOR'ed
onto screen
CX = number of times to write character
Return: nothing
Notes: all characters are displayed, including CR, LF, and BS
replication count in CX may produce an unpredictable result in graphics
modes if it is greater than the number of positions remaining in the
current row
With PhysTechSoft's PTS ROM-DOS the BH, BL, and CX values are ignored
on entry.
因此,它应该是mov cx,11
而不是mov cx,1
。
第二个mov al, hello[si]
是多余的,因为hello[si]
当时已经使用之前的相同指令加载到al
。但是,这不会影响代码的功能。
修改:添加了有关如何使用int 10h
设置和读取光标位置的信息。
您似乎还需要使用以下参数使用mov ah,2
,int 10h
更新光标位置:
INT 10 - VIDEO - SET CURSOR POSITION
AH = 02h
BH = page number
0-3 in modes 2&3
0-7 in modes 0&1
0 in graphics modes
DH = row (00h is top)
DL = column (00h is left)
Return: nothing
您可能需要使用以下参数,使用mov ah,3
int 10h
读取当前光标位置:
INT 10 - VIDEO - GET CURSOR POSITION AND SIZE
AH = 03h
BH = page number
0-3 in modes 2&3
0-7 in modes 0&1
0 in graphics modes
Return: AX = 0000h (Phoenix BIOS)
CH = start scan line
CL = end scan line
DH = row (00h is top)
DL = column (00h is left)
Notes: a separate cursor is maintained for each of up to 8 display pages
many ROM BIOSes incorrectly return the default size for a color display
(start 06h, end 07h) when a monochrome display is attached
With PhysTechSoft's PTS ROM-DOS the BH value is ignored on entry.
答案 2 :(得分:0)
.model small
.data
msg1 10,13,"hellow $"
.code
.startup
mov ah,09h
int 21h
.exit
end