Sunday, March 27, 2011

Print a string multiple times using assembly language

Objective:
Using this simple code, we can easily print a string as we need.

Instruction:

M1  DB  'Maria',0DH,0AH,'$' -> This line instructs that need to print Maria
MOV CX,10 -> The name 'Maria ' will print for 10 times

Code:

 .MODEL SMALL
.STACK 100H
.DATA

M1  DB  'Maria',0DH,0AH,'$'

.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

MOV CX,10
PRINT_LOOP:

MOV AH,9
LEA DX,M1
INT 21H
DEC CX

JNZ PRINT_LOOP

MOV AH,4CH
INT 21H

MAIN ENDP
END MAIN