unlimitedcoding
unlimitedcoding

Reputation: 31

How do I print what I want in MASM? What does mov ah, 2 before int 21h do?

I want to print my characters and variables' values and strings on my DOS screen

and I've searched for lots of stuff and most of them told me to use 'int' instruction

    .code
    main PROC
        mov dl, 'a'
        mov ah, 2h
        int 21h 
        exit
    main ENDP
    end main

I've wrote a code like this, by coping from internets.

but I don't get what 'mov ah, 2h' is for and

'int 21h' always triggers a memory error

I need to know

Upvotes: 0

Views: 5374

Answers (2)

za.asfar
za.asfar

Reputation: 1

The simplest way to answer your question about what "mov ah,2" is for,
its just like using a "cout" statement in C++ , mov ah,2 where 2 represents a
function call for printing a character on the screen and moving in ah and then "int 21h"
causes your function (2) to be executed and whatever is in data register is to be printed.

MOV DL, 'A'
MOV AH, 2
INT 21H

The code written above prints the single character 'A' on the screen. Hope that Answered your question

Upvotes: -2

Riccardo Bonafede
Riccardo Bonafede

Reputation: 606

Your program won't work because that code generate a DOS executable and modern windows version don't support them anymore (here for reference).

for what your code do, let's analize your code:

.code
    main PROC
        mov dl, 'a' ; Move character 'a' to the dl register
        mov ah, 2h  ; set the ah register to match with the 02 function code (write to STDOUT)
        int 21h ; trigger the 21h interrupt 
        exit
    main ENDP
    end main

if you want do read character in this way (that as I write before, is not anymore supported) read here, and look to the READ CHARACTER TO STDIN

EDIT: here a simple echo function:

; retrive a char from input
mov ah, 1h
int 21h 
;print that char back
mov dl, al
mov ah, 2h
int 21h

Upvotes: 0

Related Questions