15789 assember directives

Upload: jyotika-aggarwal

Post on 06-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 15789 Assember Directives

    1/28

  • 8/3/2019 15789 Assember Directives

    2/28

    Definition

    An assembler directive is a message to theassembler that tells the assembler somethingit needs to know in order to carry out theassembly process; for example, an assembledirective tells the assembler where a programis to be located in memory.

  • 8/3/2019 15789 Assember Directives

    3/28

    Equate

    EQU - This EQU directive is used to give a nameto some value or to a symbol. Each time the assembler findsthe name in the program, it will replace the name with thevalue or symbol you given to that name.

    Example:FACTOR EQU 03H ; you has to write thisstatement at the starting of your program and later in theprogram you can use this as followsADD AL, FACTOR ; When it codes thisinstruction the assembler will code it as ADDAL, 03H

    ;The advantage of using EQU in this manner is, if FACTOR isused many no of times in a program and you want to changethe value, all you had to do is change the EQU statement atbeginning, it will changes the rest of all.

  • 8/3/2019 15789 Assember Directives

    4/28

    ORIGINATE

    ORGSets the current origin to a new value. This isused to set the program or register addressduring assembly. For example, ORG 0100htells the assembler to assemble all subsequentcode starting at address 0100h.

  • 8/3/2019 15789 Assember Directives

    5/28

    IN CLUDEThis IN CLUDE directive is used to insert a block of

    source code from the named file into the currentsource module.

    Loads another source file during assembly. This

    allows you to insert an additional source file intoyour code during assembly. Included source filesusually contain common routines or data. Byusing an INCLUDE directive at the beginning of your program, you can avoid re-typing commoninformation. Included files may not contain otherincluded files. NOTE: The Device Include directive(i.e. INCLUDE 'C:\PicTools\16F877.inc' ) for thetargeted device MUST be at the beginning of yoursource code.

  • 8/3/2019 15789 Assember Directives

    6/28

    ASSUME

    The ASSUME directive is used to tell the assembler that thename of the logical segment should be used for a specifiedsegment. The 8086 works directly with only 4 physicalsegments: a Code segment, a data segment, a stack

    segment, and an extra segment.Example:ASUME CS:CODE ;This tells the assemblerthat the logical segment named CODE contains the instructionstatements for the program and should be treated as a codesegment.ASUME DS:DATA ;This tells the assemblerthat for any instruction which refers to a data in the datasegment, data will found in the logical segment DATA.

  • 8/3/2019 15789 Assember Directives

    7/28

    Define byte

    DB directive is used to declare a bytetypevariable or to store a byte in memory location.Example:1. PRICE DB 49h, 98h, 29h ;Declare an array of 3bytes, named as PRICE and initialize.2. N AME DB ABCDEF ;Declare an array of 6bytes and initialize with ASCII code for letters3. TEMP DB 100 DUP(?) ;Set 100 bytes of storage

    in memory and give it the name as TEMP, but leave the 100bytes uninitialized. Program instructions will load valuesinto these locations.

  • 8/3/2019 15789 Assember Directives

    8/28

    Define word

    DW - The DW directive is used to define avariable of type word or to reserve storage location of typeword in memory.Example:

    MULTIPLIER DW 437Ah ; this declares avariable of type word and named it as MULTIPLIER. Thisvariable is initialized with the value 437Ah when it is loadedinto memory to run.EXP1 DW 1234h, 3456h, 5678h ; this declares an

    array of 3 words and initialized with specified values.STOR1 DW 100 DUP(0); Reserve an arrayof 100 words of memory and initialize all words with0000.Array is named as STOR1

  • 8/3/2019 15789 Assember Directives

    9/28

    Define double word

    DD - The DD directive is used to declare a DWORD - ADWORD (doubleword) is made up of 32 bits (2WORDs or 4 BYTEs)

    Declaration examples:

    Dword1 DW 12345678hDword2 DW 4294967295 ;0FFFFFFFFh, themaximum possible for a DWORD

  • 8/3/2019 15789 Assember Directives

    10/28

  • 8/3/2019 15789 Assember Directives

    11/28

    Define ten byte

    New DT 11223344556677889900H-reserve 10bytes

  • 8/3/2019 15789 Assember Directives

    12/28

    GLOBAL

    GLOBAL is the other end of EXTERN: if onemodule declares a symbol as EXTERN andrefers to it, then in order to prevent linkererrors, some other module mustactually define the symbol and declare itas GLOBAL. Some assemblers use the

    name PUBLIC for this purpose.Ex GLOBAL DIVISOR:WORD

  • 8/3/2019 15789 Assember Directives

    13/28

    GROUP

    GROUP - The GROUP directive is

    used to group the logical segments named after

    the directive into one logical group segment.Ex- SMALL_SYSTEMGROUP CODE,DATA,STACK

    ASSUME CS:SMALL_SYSTEM,

    DS:SMALL_SYSTEM, SS:SMALL_SYSTEM

  • 8/3/2019 15789 Assember Directives

    14/28

    LABEL

    It gives the name to the current value inlocation counter.

    Ex ENTRY LABEL FARNEXT: MOV AL,BL

    STACK_TOP LABEL WORD

  • 8/3/2019 15789 Assember Directives

    15/28

  • 8/3/2019 15789 Assember Directives

    16/28

    NAME

    Give specific name to each module

    Ex

    Name pc_board

  • 8/3/2019 15789 Assember Directives

    17/28

    SEGMENT

    Indicate the start of logical segment

    Ex-CODESEGMEN T

    CODESEGMEN T WORD -it tells the assemblerthat we wantthe content of this segmentlocated on next word address

    CODESEGMEN

    T PUBLIC

  • 8/3/2019 15789 Assember Directives

    18/28

    OFFSET

    It determine the offset or displacement of anamed data

    ExMOV BX, OFFSET PRICES-it calculate the offsetof variable PRICES from the start of thesegment

  • 8/3/2019 15789 Assember Directives

    19/28

    SHORT

    It tells assembler that only 1bytedisplacement is needed to code a jumpinstruction.

    Ex JMP SHORT NEARBY_LABEL

  • 8/3/2019 15789 Assember Directives

    20/28

    TYPETYPE - TYPE operator instructs the assembler todetermine the type of a variable and determines

    the number of bytes specified to that variable.Example:Byte type variable assembler will give a value 1Word type variable assembler will give a value 2Double word type variable assembler will give a

    value 4ADD BX, TYPE WORD_ ARRAY ; here we want toincrement BX to point to next word in an array of

    words.

  • 8/3/2019 15789 Assember Directives

    21/28

    EVENAlign on Even Memory AddressEVEN - This EVEN directive instructs theassembler to increment the location of the counter to thenext even address if it is not already in the even address. If

    the word is at even address 8086 can read a memory in 1bus cycle.If the word starts at an odd address, the8086 will take 2 bus cycles to get the data. A series of words can be read much more quickly if they are at even

    address. When EVEN is used the location counter willsimply incremented to next address and NOP instruction isinserted in that incremented location

  • 8/3/2019 15789 Assember Directives

    22/28

    EXTRN

    It is used to declare a symbol which is notdefined anywhere in the module beingassembled, but is assumed to be defined insome other module and needs to be referredto by this one.

  • 8/3/2019 15789 Assember Directives

    23/28

    PTR

    PTR - This PTR operator is used to assign aspecific type of a variable or to a label.Example:

    IN C [BX] ; This instruction will not know whether to

    increment the byte pointed to by BX or a word pointed to byBX.IN C BYTE PTR [BX] ;increment the byte;pointed to by BXThis PTR operator can also be used to override the

    declared type of variable . If we want to access the byte in anarray WORDS DW 437Ah, 0B97h,MOV AL, BYTE PTR WORDS

  • 8/3/2019 15789 Assember Directives

    24/28

    PUBLIC

    PUBLIC - The PUBL IC directive is used to instructthe assembler that a specified name or label will be

    accessed from other modules.

    Example:PUBLIC DIVISOR, D IVIDEN D ;these twovariables are public so these are available to all

    modules.

    If an instruction in a module refers to a variable inanother assembly module, we can access thatmodule by declaring as EXTRN directive

  • 8/3/2019 15789 Assember Directives

    25/28

    END

    EN D - EN D directive is placed after the last

    statement of a program to tell the assembler

    that this is the end of the program module.The assembler will ignore any statement afteran END directive. Carriage return is required

    after the END directive

  • 8/3/2019 15789 Assember Directives

    26/28

    PROC

    PROC - The PROC directive is used to identify thestart of a procedure. The term near or far is used to

    specify the type of the procedure.

    Example:SMART PROC FAR ; This identifies thatthe start of a procedure named as SMART and instructs

    the assembler that the procedure is far .

    SMART EN DPThis PROC is used with ENDP to indicate the break of the procedure.

  • 8/3/2019 15789 Assember Directives

    27/28

    ENDP

    EN DP - EN DP directive is used along with the

    name of the procedure to indicate the end of a

    procedure to the assemblerExample:

    SQUARE_N UM PROC ; It start the procedure

    ;Some steps to find the square root of a numberSQUARE_N UM EN DP ;Here it is the End for the

    procedure

  • 8/3/2019 15789 Assember Directives

    28/28

    ENDS

    EN DS - This EN DS directive is used with name of the segment to indicate the end of that logic segment.Example:

    CODE SEGMEN T ;Hear it Start the logic;segment containing code; Some instructions statements to perform the logical;operationCODE EN DS ;End of segment named as;CODE