Chapter 4 Assemblers

Embed Size (px)

Citation preview

  • 7/31/2019 Chapter 4 Assemblers

    1/22

    Chapter 4

    Assemblers

  • 7/31/2019 Chapter 4 Assemblers

    2/22

    Assembly Language

    An Assembly language is a machinedependent,low level programminglangauges which is specific to a certain

    computer system (or a family of computersystems).

  • 7/31/2019 Chapter 4 Assemblers

    3/22

    Basic Features :

    1. Mnemonic operation codes Usage of this eliminates the need to memorize numeric

    operation codes

    enables the assembler to provide helpful daigonistics ,forexample indication of misspelt operation codes.

    2. Symbolic operands Symbolic names can be associated with data or instructions.

    Can be used as operands

    Assembler performs memory bindings to these names.

    3. Data declarations Data can be declared in variety of notations, including the

    decimal notation.

  • 7/31/2019 Chapter 4 Assemblers

    4/22

  • 7/31/2019 Chapter 4 Assemblers

    5/22

    has the followingsyntax:

    [+ ] [)]

    AREA : memory word with which the nameAREA is associated.

    AREA+5 : 5 words away from the word namedwith AREA.5 is the displacement offset fromAREA.

    AREA(4) : indexing with index register 4 (theoperand address is obtained by adding thecontents of index register 4 to the address ofAREA.

    AREA+5(4) : combination of the previous twospecifications

  • 7/31/2019 Chapter 4 Assemblers

    6/22

    Mnemonic Operation code

    Mnemonic_operation_codes.doc

    http://c/Documents%20and%20Settings/admin/Desktop/ss/Mnemonic_operation_codes.dochttp://c/Documents%20and%20Settings/admin/Desktop/ss/Mnemonic_operation_codes.doc
  • 7/31/2019 Chapter 4 Assemblers

    7/22

    Branch Condition Instruction

    Condition can be tested by a branch oncondition (BC) instruction.

    Assembly statement corresponding to ithas the format :

    BC ,

    Transfers control to the memory word with the address

    if the current value of condition codematches .

    is a character string GT,EQ.

  • 7/31/2019 Chapter 4 Assemblers

    8/22

    Assembly Language Statements

    Three kinds of statements :

    Imperative statements

    Declaration statements

    Assembler directives

  • 7/31/2019 Chapter 4 Assemblers

    9/22

    Imperative statements

    It indicates an action to be performedduring the execution of the assembledprogram.

  • 7/31/2019 Chapter 4 Assemblers

    10/22

    Declaration Statements

    The syntax of declaration statements is asfollows :

    [Label] DS ; declare storage

    [Label] DC value; declare constant

  • 7/31/2019 Chapter 4 Assemblers

    11/22

    Declaration Statements Examples

    A DS 1

    Reserves a memory area of 1 word and assocaitesthe name A with it. G DS 200

    Reserves a block of 200 memory words. Name G is associated with the first word of the

    block and can be accessed through offsets fromG,e.g G+5 is the sixth word of the memory block. ONE DC 1

    Associates the name ONE with a memory wordcontaining the value 1.

    Constants can be declared in different forms : Decimal Binary hexadecimal

  • 7/31/2019 Chapter 4 Assemblers

    12/22

    Use of Constants

    DC statement does not really implementconstants , it merely initializes memory word togiven values.

    These values are not protected by theassembler ;they may be changed by moving anew value into the word.

    AP (Assembly Program) can use constants (like

    in a HLL) in two ways : Immediate operands literals

  • 7/31/2019 Chapter 4 Assemblers

    13/22

    Immediate operands

    It should be supported by the architectureof the target machine.

    ADD AREG, 5

    Translated into an instruction with twooperands AREG and 5 as immediate

    operand.

    Supported by Intel 8086.

    t

  • 7/31/2019 Chapter 4 Assemblers

    14/22

    tera A literal is an operand with the syntax =

  • 7/31/2019 Chapter 4 Assemblers

    15/22

  • 7/31/2019 Chapter 4 Assemblers

    16/22

    Design specification of anassembler

    Four step approach to develop a designspecification for an assembler :

    1. Identify the information necessary to perform the

    task.2. Determine a suitable data structure to record the

    information.

    3. Determine the processing necessary to obtain

    and maintain the information.4. Determine the processing necessary to perform

    the task.

  • 7/31/2019 Chapter 4 Assemblers

    17/22

    Two phases of the assemblers Synthesis Phase and Analysis Phase

    Synthesis Phase

    MOVER BREG,ONE

    Following information is needed to synthesizethe machine instruction corresponding to thisstatement:

    Address of the memory word with which nameONE is associated.

    Machine operation code corresponding to themnemonic MOVER.

  • 7/31/2019 Chapter 4 Assemblers

    18/22

    Two data structures during theSynthesis phase:

    Symbol table Each entry of the symbol table has two primary

    fields Name and address

    This table is built by the analysis phase Mnemonic Table

    Has two primary fields Mnemonic and opcode.

    The synthesis phase uses these tables to obtain themachine address with which a name is associated andthe machine opcode corresponding to a mnemonic.

    Tables have to be searched with the symbol name andthe mnemonic as keys.

  • 7/31/2019 Chapter 4 Assemblers

    19/22

    Analysis Phase Primary function

    Build the symbol table. It must determine the address with which the

    symbolic names in a program are associated.

    It is possible to determine the address of thefirst instruction in the program, others may beinferred.

  • 7/31/2019 Chapter 4 Assemblers

    20/22

    Memory Allocation

    Fixing the address of all program elementspreceding it is called Memory Allocation.

    Location Counter (LC) To implement memory allocation LC data

    structure is used. It always made to contain the address of the next

    memory word in the target program.

    It is initialized to the constant specified in the

    START statement. LC Processing

    Process involved in maintaining the location counter isknown as LC Processing.

  • 7/31/2019 Chapter 4 Assemblers

    21/22

    Tasks performed by the analysisand synthesis phase are as follows

    Analysis Phase1. Isolate the label, mnemonic opcode and

    operand fields of a statement.

    2. If the label is present enter the pair (symbol,) in a new entry of the symboltable.

    3. Check validity of the mnemonic opcode

    through a look-up in the Mnemonics table.4. Perform LC processing i.e. update the value

    contained in LC by considering the opcodeand operands of the statement.

  • 7/31/2019 Chapter 4 Assemblers

    22/22

    Synthesis Phase

    1. Obtain the machine opcodecorresponding to the mnemonic from theMnemonics table.

    2. Obtain address of a memory operandfrom the Symbol table.

    3. Synthesize a machine instruction or themachine form of a constant , as the casemay be.