首页 > 解决方案 > 如何在特定列打印包含多行的整个字符串?

问题描述

这是我的代码:

data segment

     letter_a db   '  __ _  ',10,13
              db   ' / _` | ',10,13
              db   '| (_| | ',10,13
              db   ' \__,_| ',10,13
              db   '        '                                  
    opening_end db 0             
    pointer db 10         

ends

stack segment
    dw   128  dup(0)
ends

code segment
start:
    mov ax, data
    mov ds, ax
    mov es, ax

    call print_opening

    ; wait for any key....    
    mov ah, 1
    int 21h

    call print_opening

    ; wait for any key....    
    mov ah, 1
    int 21h

    mov ax, 4c00h ; exit to operating system.
    int 21h    
ends

proc print_opening   
    pusha

    mov al, 1 
    mov bh, 0
    mov bl, 3 

    ; I calculate length
    lea cx, opening_end   
    lea dx, letter_a
    sub cx, dx               

    mov dh, 3 ; row
    mov dl, [pointer] ; col
    lea bp, letter_a                           

    mov ah, 13h
    int 10h              

    mov ah, 8
    int 21h

    add [pointer], 10
    popa
    ret
endp print_opening

end start 

问题是它只在我选择的列中开始字符串的第一行,然后返回到第 0 列。有没有办法随时缩进整个字符串?
我希望能够像在代码中一样更改它,而不仅仅是在数据段中设置缩进。
我真的希望这是可能的。提前致谢!

标签: assemblydosx86-16biosascii-art

解决方案


鉴于需要一个循环来完成此操作,因此在数据行中使用换行和回车是没有用的。

letter_a    db   '  __ _  '
            db   ' / _` | '
            db   '| (_| | '
            db   ' \__,_| '
            db   '        '
opening_end db   0             
pointer     db   10  

一旦在opening_end读取终止的 0,循环就会结束。

    mov     cx, 8     ; Every row has 8 characters
    mov     dh, 3     ; row on the screen to start
    mov     dl, [pointer] ; col on the screen is fixed
    lea     bp, letter_a
Again:
    mov     bx, 0003h ; display page 0 and attribute 03h
    mov     ax, 1301h ; function 13h and write mode 1
    int     10h
    add     bp, cx    ; To next line in the data
    inc     dh        ; To next row on the screen
    cmp     [es:bp], ch  ; CH=0
    jne     Again

推荐阅读