1

再会。我是汇编语言的新手,我正在尝试在 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
4

3 回答 3

0

如果您正在为 DOS 进行汇编编程,您应该熟悉一些常用的中断,例如int 10hint 21h. 对于每个中断子函数,都有一组相应的参数,您需要通过一个或多个寄存器将其传递给它。

您粘贴的示例代码中使用的中断是“WRITE CHARACTER AND ATTRIBUTE AT CURSOR POSITION”,您可以在此处找到它的描述。

为了显示具有颜色属性的字符串,您必须在循环中迭代字符串并使用适当的参数为每个字符调用中断。

于 2013-03-10T15:31:28.860 回答
0

与任何编程语言一样,汇编语言是任意设计决策的结果。有时将特定寄存器用作中断调用输入寄存器(优化)可能是有原因的,但很多时候不是,您只需将接口(此处int 10hint 21h)视为理所当然。

与您的几个感叹号问题!!!!!!!!!!!(我假设有 11 个感叹号)相关,您的int 10中断调用中的参数不正确:

mov cx,11

根据Ralf Brown 的中断列表, 的参数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.
于 2013-03-10T16:25:00.630 回答
0
.model small
.data
msg1 10,13,"hellow $"
.code
.startup
mov ah,09h
int 21h
.exit
end
于 2013-10-26T03:07:54.277 回答