Monday, April 25, 2016

Description and Example of Named Constants


EQU (Equates)

To assign a name to a constant, we can use the EQU (equates) pseudo-op. THe syntax is 

name                            EQU                                     constant


For Example :   the statement

LF                         EQU                            0AH


assigns the name LF to 0Ah, the ASCII code of the line feed character. The name LF may now be used in place of 0Ah anywhere in the program. Thus, the assembler translates the instructions

MOV            DL, 0AH

and 

MOV DL,LF

into the same machine instruction

The symbol on the right of an EQU can also be a string 

Example :

PROMPT EQU  'TYPE YOUR NAME'

Then instead of

MSG       DB                    'TYPE YOUR NAME'

we could say

MSG    DB                    PROMPT

Note : no memory is allocated for EQU names.


 

Description and Example of Array

** In assembly language, an array is just a sequence of memory bytes or word.

For Example : To define a three-byte array called B_ARRAY, whose initial values are 10h, 20h, and 30h, we can write,

B_ARRAY                  DB                                   10H,20H,30H

The name B_ARRAY  is associated with the first of these bytes, B_ARRAY+1 with the second, and B_ARRAY+2 with the third. If the assembler assigns the offset address 0200h to B_ARRAY, then memory would look like this : 

Symbol                         Address                           Contents

B_ARRAY                            200h                                 10h

B_ARRAY+1                        201h                                 20h 

B_ARRAY +2                       202h                                 30h 

In the same way, an array of words may be defined.

Example : 

W_ARRAY                       DW                                 1000,40,29887,329

sets up an array of four words, with initial value 1000, 40,29887, and 329.
The initial word is associated with the name W_ARRAY, the next one with W_ARRAY+2, the next with B_ARRAY+4, and so on. If the array starts at 0300h, it will look like this : 



Symbol                          Address                           Contents

W_ARRAY                            0300h                                 1000d

W_ARRAY+2                        0302h                                 40d

W_ARRAY +4                       0304                                  29887d

W_ARRAY +6                      0306h                                 329d 


High and low Bytes of a Word

Sometimes we need to refer to the high and low bytes of a word variable.  Suppose we define 

WORD1                        DW                           123H

The low byte of WORLD1 contains 34h, and the high byte contains 12h. The low byte has symbolic address WORD1, and the high byte has symbolic address WORD1+1.

Character Strings

An array of ASCII codes can be initialized with a string of characters.

Example : 

LETTERS                                       DB                           'ABC'

is equivalent to

LETTERS                 DB                    41H,42H,43H


Inside a String the assembler differentiates between upper and lower case. Thus, the string "abc" is translated into three bytes with values 61h,62h, and 63h

It is possible to combine characters and number in one definition;

Example :

MSG     DB                        'HELLO', 0AH, 0DH, 'S'


is equivalent to  

MSG DB                            48H, 45H, 4CH, 4CH, 4FH, 0AH, 0DH, 24H

Description and Example of Program word variable

Word Variables:
 

The assembler directive for defining a word variable has the following form:

           name D W                            initial_value

the pseudo-op     D W    MEANS "Define word. "for example 

          W R D    D W         - 2

as with byte variables , a question mark in place of an initial value means an uninitialized word . the decimal range of initial values that can be specified is - 32768  to 32767  for a signed interpretation ,or  0 to   65535  for an unsigned interpretation.

Description and Example of Program variable

Variables:
 
Variable play the same role in assembly language that they do in high-level languages. Each variable
 has a data type and is assigned a memory address by the program .The data -defining pseudo-op can
 be used to set aside one or more data items of the given type .


                 in this section we use D B and  D W  to define byte variable , word variable ,and arrays of byte ,word are used in chapter 18 in connection with multiple - precision and noninteger operations  

Description and Example of Program Byte variable

Byte variable :    

The assembler directive that defines a byte variable takes the following form:
        name DB    .                   initial_value
where the pseudo-op DB stands for "Define Byte"
             for example ,
This directive causes the assembler to associate a memory byte with the name ALPHA, and initialize it to 4,A question mark("?") used in place of an initial value sets aside an uninitialized byte ; for example ,
       BYTE     DB
The decimal range of initial values that can be specified is -128 to 127 if a signed  interpretation is being given ,or 0 to 255 for an unsigned interpretation .These are the ranges of values that fit in a byte.
     
                           
**Characters : Characters and character strings must be enclosed in single or double quotes; For example, "A" or 'hello'. Characters are translates into their ASCII codes by the assembler, so there is no difference between using "A" and 4h (the ASCII  code for "A") in a program.

table 4.1   Data-Defining Pseudo-ops

Pseudo-op                              Stands for

DB                                           define byte

DW                                         define word

DD                                         define doubleword  (two consecutive words)

DQ                                         define quadword (four consecutive words) 

DT                                          define tenbytes (ten consecutive bytes)

Description and Example of Program Data

**Numbers : A binary number is written as a bit string followed by the letter "B" or "b"; for example,  1010B


A decimal number must begin with a decimal digit and end with the letter "H" or "h"; For Example, 0ABCH  (the reason for this is that the assembler would be unable to tell whether a symbol such as "ABCH" represents the variable name "ABCH" or the hex number ABC).


Any of the preceding numbers may have an optional sign. Here are examples of legal and illegal numbers for MASM.



Number                                          Type

11011                                              decimal

11011B                                            binary

65223                                              decimal

-21843D                                          decimal

1,234                                                illegal-contains a nondigit character hex

1B4DH                                             illegal hex number-doesn't end in "H"

1B4D                                                 illegal hex number -doesn't begin with                                            
FFFFH                                              a decimal digit

0FFFFH                                            hex