Search code examples
assemblydosx86-16biosascii-art

How do I print a whole string with multiple lines at a specific column?


This is my code:

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 

The problem is it only starts the first line of the string in my chosen column and then goes back to column zero. Is there a way to indent the whole string whenever I want to?
I want to be able to change it as I am in my code, and not just set the indentation in the data segment.
I really hope this is possible. Thanks in advance!


Solution

  • It's useless to have linefeed and carriage return in the data lines given that a loop is required to pull this off.

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

    The loop will end as soon as it reads the terminating 0 at opening_end.

        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