Friday, January 17, 2014

What is 10,13 in Assembly Language variable declaration?



In many assembly language programs written for x86 architecture, the values 10, 13 are written in data segment declaration.
e.g.

    .data
     message db 10, 13, 'abcd$'

Here the string will be declared and it will have the values declared in front of it. The actual array will be,
message:

0AH
0DH
41H
42H
43H
44H
24H
10         13         'a'          'b'         'c'         'd'         '$'

The respective ASCII characters of these values will be printed till '$'. It is considered as end of the string character. 'a' 'b' 'c' 'd' are printable characters but 10 & 13 are non-printable characters .
In short,they are control characters chart below.(Reference -Wikipedia).


10 is called as LF or Line Feed or new line and 13 is called as CR or Carriage return.
These character are used to control the cursor position. The 10 shifts cursor on new line with same column no. and 13 returns the cursor to its initial position of line that is at start of the line!

So, every time you make use of these control characters as the part of string or any array. It shifts the cursor to new line and at the start of the line.

(Note – the term carriage return (CR) is taken from printer's operation. When printer finishes one line printing, it shifts to new line but it prints head moves to start of new line).

LF & CR are equivalent to \n & \r used is print statement of high level programming languages.

Lets take an Example.

Declare variable as

   .data
      message db 10,13,'Welcome$'

and print using,

    MOV AH, 09H
  LEA DX, MESSAGE
  INT 21H

Now make some changes in declaration as,

   .data
   message db 10, 13, 'Wel', 10, 13, 'come$'

Check the output by printing this message.

1 comment: