Monday, November 19, 2012

ASSEMBLER DIRECTIVES AND OPERATORS



The logical errors or other programming errors are not found by the assembler. For completing all these tasks, an assembler needs some hints from the programmer. These types of hints are given to the assembler using some predefined alphabetical strings called assembler directives, which helps the assembler to correctly understand the assembly language program to prepare the codes.
Another type of hint which helps the assembler to assign a particular constant with a label or initialize particular memory locations or labels with constants is an operator.

  • DB: Define Byte: The DB directive is used to reserve byte or bytes of memory locations in the available memory.
  • DW: Define Word: The DW directive serves the same purposes as the DB directive, but it makes the assembler reserves the number of memory words (16bit) instead of bytes.
  • DQ: Define Quadword: This directive is used to direct the assembler to reserve 4 words (8bytes) of memory for the specified variable and may initialize it with the specified values.
  • DT: Define Ten Bytes: The DT directive directs the assembler to define the specified variable requiring 10-bytes for its storage and initialize the 10-bytes with the specified values.
  • ASSUME: Assume Logical Segment Name: The ASSUME directive is used to inform the assembler, the names of the logical segments to be assumed for different segments used in the program.
  • END: END Of Program: The END directive marks the end of an assembly language program.
  • ENDP: END Of Procedure: The ENDP directive is used to indicate the end of a procedure.  
                        PROCEDURE STAR
                                           :

                              STAR ENDP    //indicates the end of procedure STAR
  • ENDS: END Of Segment: This directive marks the end of a logical segment.        
                              DATA   SEGMENT                

                                          :

                              DATA ENDS    //indicates the end of segment DATA
  • EVEN: Align On Even Memory Address: The EVEN directive updates the location counter to the next even address, if the current location counter contents are not even, and assigns the following routine or variable or constant to that address. If the content of the location counter is already even, then the procedure will be assigned with the same address.

  • EQU: Equate: The directive EQU is used to assign a label with a value or symbol. The use of this directive is just to reduce the recurrence of the numerical values or constants in the program code.
           LABEL  EQU 0500H

  • EXTERN: External and PUBLIC: Public: The directive EXTERN informs the assembler that the names, procedures and labels declared after this directive have already been defined in some other assembly language module.

  • GROUP: Group the Related Segments: This directive is used to form logical groups of segments with similar purpose or type.
                          PROGRAM GROUP CODE, DATA, STACK //this statement directs the loader/linker to prepare an EXE file such that CODE, DATA, STACK segment must lie within a 64byte memory segment that is named as PROGRAM

  • LABEL: The LABEL directive is used to assign a name to the current content of the location counter. A LABEL directive can be used to make a FAR jump. The label directive can be used to refer to the data segment along with the data type, byte or word.

DATA       SEGMENT
DATAS DB 50H DUP (?)
DATA-LAST LABEL BYTE FAR
DATA ENDS

After reserving 50H locations for DATAS, the next location will be assigned a label DATA-LAST and its type will be byte and far.
 
  • LENGTH: Byte Length Of A Label: This directive is used to refer to the length of a data array or a string. Not available in MASM.
  • LOCAL: The label, variables, constants or procedures declared LOCAL in a module are to be used only by that particular module.
  • NAME: Logical Name Of A Module: The NAME directive is used to assign a name to an assembly language program module.
  • OFFSET: Offset Of A Label: When the assembler comes across the OFFSET operator along with a label, it first computes the 16-bit displacement of the particular label, and replaces the string ‘OFFSET LABEL’ by the computed displacement.
  • ORG: Origin: The ORG directive directs the assembler to start the memory allotment for the particular segment, block or code from the declared address in the ORG statement.
  • PROC: Procedure: The PROC directive marks the start of a named procedure in the statement. Also the types FAR and NEAR specifies the type of the procedure.
  • PTR: Pointer: The POINTER operator is used to declare the type of a label, variable or memory operand. The operator PTR is prefixed by either BYTE (8-bit quantity) or WORD (16-bit quantity).
  • SEGMENT: Logical Segment: The SEGMENT directive marks the starting of a logical segment. The started segment is also assigned a name, i.e. label, by this statement.
  • SHORT: The SHORT operator indicates the assembler that only one byte is required to code the displacement for a jump. This method of specifying jump address saves memory.
  • TYPE: The TYPE operator directs the assembler to decide the data type of the specified label and replaces the TYPE label by the decided data type.

  • GLOBAL: The labels, variables, constants or procedures declared GLOBAL may be used by other modules of the program.
  • ‘+ & -‘Operators: These operators represent arithmetic addition and subtraction respectively. And are typically used to add or subtract displacements (8 or 16 bit) to base or index registers or stack or base pointers.

  • FAR PTR: This directive indicates the assembler that the label following FAR PTR is not available within the same segment and the address of the bit is of 32 bits i.e. 2 bytes offset followed by 2 bytes.


  • NEAR PTR: This directive indicates that the label following NEAR PTR is in the same segment and need only 16 bit i.e. 2 byte offset to address it. A NEAR PTR label is considered as default if a label is not preceded by NEAR PTR or FAR PTR.

1 comments:

This comment has been removed by the author.

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More