Search code examples
assemblyx86dostasm

How to center text in TASM?


Hi guys. I have a problem here in TASM. Here I have codes using ASCII code to display a name. How will I put the output in the center?.

.model small
.stack 200h
.code

start:

Mov ah, 2
Mov dl, 68
Int 21h

Mov ah, 2
Mov dl, 97
Int 21h
Mov ah, 2
Mov dl, 114
Int 21h

mov ah, 4ch
mov al,00h
int 21h

end start

Solution

  • Use the GET CURSOR POSITION AND SIZE and SET CURSOR POSITION interrupts for that:

    mov ah,3    ; Get the current cursor position
    mov bh,0
    int 10h
    
    mov ah,2    ; Set cursor position
    mov bh,0
    mov dl,39   ; New column. In an 80 column text mode this will just about center
                ; the 3 characters 
    ; We wanto to stay on the same row, so we don't change dh
    int 10h