Search code examples
assemblyfasm

Assembly: Change background and foreground color with output string


So I have made a program wherein i could change the background color using the 06h function. I tried to place a string after then delay and loop, I don't understand why the string is moving to the right when I still don't place any code that could make the text move anywhere. Can somebody explain this to me? Thanks.

 LOOPS:
 MOV AH, 06h    ; Scroll up function
 XOR AL, AL     ; Clear entire screen
 XOR CX, CX     ; Upper left corner CH=row, CL=column
 MOV DX, 184FH  ; lower right corner DH=row, DL=column 
 MOV BH, 1Eh    ; YellowOnBlue
 INT 10H

 MOV AH, 9
 MOV DX, OUTPUT
 INT 21H
 CALL DELAY 
 JMP LOOPS

 DELAY:
 *some codes*

  OUTPUT DB 'HELLO', 24H

Solution

  • You can easily keep using the DOS output function and still have the text on the same spot if you preserve and restore the cursor around the DOS call.

    mov bh, 0     ;Display page 0
    mov ah, 03h   ;Get Cursor
    int 10h       ;BIOS returns the cursor position in DX (Shape in CX)
    push dx       ;Save on stack
    
    MOV AH, 9
    MOV DX, OUTPUT
    INT 21H
    
    pop dx        ;Restore from stack
    mov bh, 0     ;Display page 0
    mov ah, 02h   ;Set Cursor
    int 10h
    
    CALL DELAY 
    JMP LOOPS