Ali Akber Faiz
Ali Akber Faiz

Reputation: 127

Print each word on separate line

I'm unable to understand a few lines in the code I'm going to provide below.

int sc=-1;
while (strings[sc++]!=0)
{
_asm{
PUSH SI;
MOV SI,sc; get pointer
MOV DL,strings[SI]; get character 
CMP DL,' '; if not space
JNE next
MOV AH,2H; display new line 
MOV DL,10H; what is significance of this line? 
INT 21H; And this one 
MOV DL,13H ; what is significane of this line 
next: MOV AH,2H; display character
INT 21H;
POP SI;
}
}

there are a couple of lines I have written in their comments whose significance I am unaware of. Also I m very new to assembly language programming and this is something i read in a text book

Upvotes: 2

Views: 125

Answers (1)

Sep Roland
Sep Roland

Reputation: 39166

MOV DL,10H; what is significance of this line? 

The 10H is most probably a typo that should have read 10 which is the ASCII code for a linefeed. It moves the cursor 1 row down on the screen.

MOV DL,13H ; what is significane of this line 

The 13H is most probably a typo that should have read 13 which is the ASCII code for a carriage return. It moves the cursor to the far left on the screen.

INT 21H; And this one 

The INT 21H instruction is a DOS system call that performs the function for whom you've put the function number in the AH register.


The whole code will output the current character if it is not a space character.
If it is a space character, then the code performs a newline sequence (carriage return + linefeed).

Because of the post-increment sc++ that happened before this inline assembly code, the code will only work fine if the MOV DL,strings[SI] instruction is replaced with MOV DL,strings[SI-1].


Thanks to interjay for catching the typos.

Upvotes: 2

Related Questions