Search code examples
assemblynewlinedosx86-16

Write lines in assembly with out going back to the start of the line (stair step text)


I can't find a way to write words in assembly in a waterfall struct, example:

one
   two
      three

I tried to seprate between 10 and 13 but it didnt work. here is the code so far:

.MODEL SMALL
.STACK 100h
.DATA
MyProgram DB 'word1',10,'word2',10,'word3','$'    


.CODE

ProgStart:
MOV AX,@DATA
MOV BX,OFFSET MyProgram
MOV DS,AX

MOV AH,9
MOV DX,OFFSET MyProgram
INT 21h

MOV AH,4ch
INT 21h

Solution

  • You will have to go back to the start of the line because you need a line break. By nature, line break moves cursor to the beginning of the next line. With linebreaks you need one blank space and a counter to display the blank space n times. This counter increases with every line you display. Example made in EMU8086 (just copy, paste and run) :

    .STACK 100h
    .DATA
    
    text   DB 'hello world',13,10,'$'
    space  DB ' $' ;BLANK SPACE.
    spaces dw 1  ;COUNTER FOR BLANK SPACES.
    
    
    .CODE
    
    MOV AX,@DATA
    MOV DS,AX
    
      mov bx,10 ;HOW MANY LINES TO DISPLAY.
    
    display_text:  
    
      mov cx, spaces   
    display_spaces: 
      mov ah, 9
      mov dx, offset space
      int 21h
      loop display_spaces ;CX-1. IF CX!=0 : DISPLAY NEXT SPACE.
    
      inc spaces ;MOVE NEXT INDENT ONE SPACE TO THE RIGHT.
    ;DISPLAY TEXT.
      MOV AH,9
      MOV DX,OFFSET text
      INT 21h         
    
      dec bx ;LINES COUNTER.
      mov cx, bx
      loop display_text
    
    
    MOV AH,4ch
    INT 21h
    

    If you want to indent by one space, increase the counter by 1, if you want to indent by two spaces, increase by 2, and so on.

    Now WITHOUT line breaks, by using GOTOXY, this way you don't need to go back to the beginning of the line because there are no line breaks :

    .STACK 100h
    .DATA
    
    text  DB 'hello world',13,10,'$'
    row   db 1  ;LINE NUMBER.
    col   db 1
    
    .CODE
    
    MOV AX,@DATA
    MOV DS,AX
    
      mov cx,10 ;HOW MANY LINES TO DISPLAY.
    
    display_text:  
    ;GOTOXY.
      mov ah, 2
      mov bh, 0
      mov dl, col
      mov dh, row
      int 10h ;BIOS SCREEN SERVICES.
    ;DISPLAY TEXT.
      MOV AH,9
      MOV DX,OFFSET text
      INT 21h         
    
      inc row ;Y COORDINATE ONE LINE DOWN.
      inc col ;X COORDINATE ONE COLUMN RIGHT.
      loop display_text
    
    
    MOV AH,4ch
    INT 21h