【问题标题】:How do I print a whole string with multiple lines at a specific column?如何在特定列打印包含多行的整个字符串?
【发布时间】:2019-05-05 18:44:10
【问题描述】:

这是我的代码:

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 列。有没有办法随时缩进整个字符串?
我希望能够像在代码中一样更改它,而不仅仅是在数据段中设置缩进。
我真的希望这是可能的。提前致谢!

【问题讨论】:

    标签: assembly dos x86-16 bios ascii-art


    【解决方案1】:

    考虑到需要一个循环来实现这一点,所以在数据行中有换行和回车是没有用的。

    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
    

    【讨论】:

    • 嘿,非常感谢您的回复,但是,我运行了您的代码,它仍然只显示到字符串的第一行,现在其余的不在第一列中它只是不在那里。
    • @SurfingSky cm [bp], ch 正在使用 SS: 段,但您的数据位于 ES:。已更正!
    • 对不起,如果我很烦人,但现在它只是显示错误的参数错误,
    • @SurfingSky 您可能必须使用 cmp es:[bp], ch 之类的替代语法或将 ES: 放在单独的行上。如果需要,请查阅汇编手册。
    • 非常感谢,您刚刚保存了我的学校项目(您可以看出汇编不是我的首选语言)谢谢!
    猜你喜欢
    • 1970-01-01
    • 2013-08-05
    • 2019-04-16
    • 1970-01-01
    • 2014-09-22
    • 2019-02-25
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    相关资源
    最近更新 更多