Rotemika
Rotemika

Reputation: 61

Printing message in specific place on screen with DOS int 21h in graphic mode

I want to print out strings in assembly, I've managed to print out a string but I can't figure out how to print it in a specific place on the screen

This is the code I'm using:

IDEAL
MODEL small
STACK 100h
DATASEG

message db 'Hello World',10,13,'$'

CODESEG
start:
    mov ax, @data
    mov ds, ax

       ;graphic mode:;
    mov ax, 13h
    int 10h

    pop ds
    mov dx, offset message
    mov ah, 9h
    int 21h

exit:
    mov ax, 4c00h
    int 21h
END start

The graphic mode is because this is part of a bigger project I'm working on but to my understanding it shouldn't be a problem.

This program does print out the message it just prints it out on the upper right corner of my screen. I would very much like to know how to print the message in a specific place and also determine its size if possible.

Upvotes: 2

Views: 1232

Answers (1)

Fifoernik
Fifoernik

Reputation: 9899

You just have to position the cursor where you need the string to appear.
The screen 13h has 40 columns and 25 rows.
Use BIOS function 02h:

mov dl, 20    ;Center column
mov dh, 12    ;Center row
mov bh, 0     ;Display page 0
mov ah, 02h   ;SetCursor
int 10h
mov dx, offset message
mov ah, 09h   ;DispayString
int 21h

pop ds

What's this doing in your code?


...also determine its size if possible.

Write the following:

message db 'Hello World',10,13,'$'
size    equ ($-1)-message

$ is the position where the current line (code) starts.
Here size will get 13 bytes.

Then use it like:

mov cx, size

Upvotes: 1

Related Questions